00001 // Package : omniIFR 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 omniIFR application. 00008 // 00009 // omniIFR 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 // omniIFR 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 OMNIIFR__DAEMON_UNIX_H 00025 #define OMNIIFR__DAEMON_UNIX_H 00026 00027 #ifdef __WIN32__ 00028 # error("This file is not intended for Windows.") 00029 #endif 00030 00031 namespace Omniifr { 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 00077 static void log(const char* message); 00078 00079 private: 00081 void fork(); 00082 00086 void redirectStreamsTo(const char* filename); 00087 00091 int openFileFor(int fd, const char* filename, int flags); 00092 00096 void checkPidfileOrShutdown(); 00097 00098 void writePidfile(); 00099 00104 int waitForChild(); 00105 00107 void notifyParent(int status); 00108 }; 00109 00110 } // end namespace Omniifr 00111 00112 #endif // OMNIIFR__DAEMON_UNIX_H