00001 // Package : omniEvents
00002 // daemon_unix.h Created : 2004/06/26
00003 // Author : Alex Tingle
00004 //
00005 // Copyright (C) 2004 Alex Tingle.
00006 //
00007 // This file is part of the omniEvents application.
00008 //
00009 // omniEvents is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // omniEvents is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023
00024 #ifndef OMNIEVENTS__DAEMON_UNIX_H
00025 #define OMNIEVENTS__DAEMON_UNIX_H
00026
00027 #ifdef __WIN32__
00028 # error("This file is not intended for Windows.")
00029 #endif
00030
00031 namespace OmniEvents {
00032
00037 class DaemonImpl
00038 {
00039 public:
00040 static DaemonImpl _inst;
00041
00042 char* _tracefile;
00043 bool _foreground;
00044 char* _pidfile;
00045 int _pipe[2];
00046 bool _havePidfile;
00047 bool _haveParent;
00048 bool _haveSyslog;
00049
00050 DaemonImpl();
00051 ~DaemonImpl();
00052
00053 void tracefile(const char* val);
00054 void pidfile(const char* val);
00055 void foreground(bool val);
00056
00058 void initialize(int&,char**&);
00059
00063 void daemonize();
00064
00069 void runningOk();
00070
00074 void shutdown(int status);
00075
00081 static void log(const char* message);
00082
00083 private:
00085 void fork();
00086
00090 void redirectStreamsTo(const char* filename);
00091
00095 int openFileFor(int fd, const char* filename, int flags);
00096
00100 void checkPidfileOrShutdown();
00101
00102 void writePidfile();
00103
00108 int waitForChild();
00109
00111 void notifyParent(int status);
00112 };
00113
00114 } // end namespace OmniEvents
00115
00116 #endif // OMNIEVENTS__DAEMON_UNIX_H
1.2.15