My Project
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Properties Macros
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 : private NonCopyable
67 {
68 public:
72 
77  static UPtr create();
78 
83  void close_fds() noexcept;
84 
88  void reset_signals() noexcept;
89 
94  void set_umask(mode_t mask) noexcept;
95 
104  void set_working_directory(std::string const& working_directory);
105 
119  void daemonize_me();
120 
121  ~Daemon() noexcept;
122 
123 private:
124  Daemon(); // Class is final, instantiation only via create()
125 
126  std::unique_ptr<internal::DaemonImpl> p_;
127 };
128 
129 } // namespace util
130 
131 } // namespace unity
132 
133 #endif