OmniEvents
daemon_unix.h
Go to the documentation of this file.
1 // Package : omniEvents
2 // daemon_unix.h Created : 2004/06/26
3 // Author : Alex Tingle
4 //
5 // Copyright (C) 2004 Alex Tingle.
6 //
7 // This file is part of the omniEvents application.
8 //
9 // omniEvents is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // omniEvents is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 
24 #ifndef OMNIEVENTS__DAEMON_UNIX_H
25 #define OMNIEVENTS__DAEMON_UNIX_H
26 
27 #ifdef __WIN32__
28 # error("This file is not intended for Windows.")
29 #endif
30 
31 namespace OmniEvents {
32 
38 {
39 public:
40  static DaemonImpl _inst;
41 
42  char* _tracefile;
43  bool _foreground;
44  char* _pidfile;
45  int _pipe[2];
46  bool _havePidfile;
47  bool _haveParent;
48  bool _haveSyslog;
49 
50  DaemonImpl();
51  ~DaemonImpl();
52 
53  void tracefile(const char* val);
54  void pidfile(const char* val);
55  void foreground(bool val);
56 
58  void initialize(int&,char**&);
59 
63  void daemonize();
64 
69  void runningOk();
70 
74  void shutdown(int status);
75 
81  static void log(const char* message);
82 
83 private:
85  void fork();
86 
90  void redirectStreamsTo(const char* filename);
91 
95  int openFileFor(int fd, const char* filename, int flags);
96 
100  void checkPidfileOrShutdown();
101 
102  void writePidfile();
103 
108  int waitForChild();
109 
111  void notifyParent(int status);
112 };
113 
114 } // end namespace OmniEvents
115 
116 #endif // OMNIEVENTS__DAEMON_UNIX_H