My Project
Daemon.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Michi Henning <michi.henning@canonical.com>
17  */
18 
19 #ifndef UNITY_UTIL_DAEMON_H
20 #define UNITY_UTIL_DAEMON_H
21 
22 #include <unity/util/DefinesPtrs.h>
23 #include <unity/util/NonCopyable.h>
24 
25 #include <sys/types.h>
26 
27 namespace unity
28 {
29 
30 namespace util
31 {
32 
33 namespace internal
34 {
35 class DaemonImpl;
36 }
37 
66 class UNITY_API Daemon final
67 {
68 public:
70  NONCOPYABLE(Daemon);
73 
78  static UPtr create();
79 
84  void close_fds() noexcept;
85 
89  void reset_signals() noexcept;
90 
95  void set_umask(mode_t mask) noexcept;
96 
105  void set_working_directory(std::string const& working_directory);
106 
120  void daemonize_me();
121 
122  ~Daemon() noexcept;
123 
124 private:
125  Daemon(); // Class is final, instantiation only via create()
126 
127  std::unique_ptr<internal::DaemonImpl> p_;
128 };
129 
130 } // namespace util
131 
132 } // namespace unity
133 
134 #endif
Helper class to turn a process into a daemon.
Definition: Daemon.h:66
Top-level namespace for all things Unity-related.
Definition: Version.h:37
#define UNITY_DEFINES_PTRS(classname)
Macro to add smart pointer definitions to a class.
Definition: DefinesPtrs.h:52