OmniEvents
|
Utility class that contains various methods for running omniEvents as a Unix daemon. More...
#include <daemon_unix.h>
Public Member Functions | |
DaemonImpl () | |
~DaemonImpl () | |
void | tracefile (const char *val) |
Set _tracefile. More... | |
void | pidfile (const char *val) |
Set _pidfile. More... | |
void | foreground (bool val) |
Set _foreground. More... | |
void | initialize (int &, char **&) |
Does nothing on Unix. More... | |
void | daemonize () |
Puts the current process into the background. More... | |
void | runningOk () |
Called to signal that all startup operations have completed OK. More... | |
void | shutdown (int status) |
Exit handler called (indirectly) by ::on_exit() - shuts down the daemon. More... | |
Static Public Member Functions | |
static void | log (const char *message) |
Callback, used as a parameter to omniORB::setLogFunction(). More... | |
Public Attributes | |
char * | _tracefile |
The tracefile name (if any). More... | |
bool | _foreground |
TRUE for debug mode (run in foreground) More... | |
char * | _pidfile |
The pidfile name (if any). More... | |
int | _pipe [2] |
Unnamed pipe for child->parent comms. More... | |
bool | _havePidfile |
Is there a pidfile for us to clean up? More... | |
bool | _haveParent |
Is there a parent for us to clean up? More... | |
bool | _haveSyslog |
Should we close syslog before quitting? More... | |
Static Public Attributes | |
static DaemonImpl | _inst |
Private Member Functions | |
void | fork () |
Performs the actual fork. More... | |
void | redirectStreamsTo (const char *filename) |
Redirect stdout & stderr to filename. More... | |
int | openFileFor (int fd, const char *filename, int flags) |
Opens a (new?) file called 'filename' for writing, and uses it to hijack stream 'fd'. More... | |
void | checkPidfileOrShutdown () |
If pidfile exists & contains a running process then shutdown() (Unix). More... | |
void | writePidfile () |
int | waitForChild () |
Called by the parent process (Unix). More... | |
void | notifyParent (int status) |
Tells the parent to exit with the given status (Unix). More... | |
Utility class that contains various methods for running omniEvents as a Unix daemon.
Features: pidfile support, forking, redirect omniORB trace to syslog (or tracefile).
Definition at line 37 of file daemon_unix.h.
OmniEvents::DaemonImpl::DaemonImpl | ( | ) |
Definition at line 119 of file daemon_unix.cc.
OmniEvents::DaemonImpl::~DaemonImpl | ( | ) |
Definition at line 122 of file daemon_unix.cc.
|
private |
If pidfile exists & contains a running process then shutdown() (Unix).
Also shuts down if pidfile is inaccessible.
Definition at line 298 of file daemon_unix.cc.
References STRERR_FILE_LINE.
void OmniEvents::DaemonImpl::daemonize | ( | ) |
Puts the current process into the background.
Redirects the omniORB log output to syslog (or 'tracefile', if it is set).
Definition at line 158 of file daemon_unix.cc.
References PACKAGE_NAME, omniORB::setLogFunction(), OmniEvents::shutdown0(), OmniEvents::shutdown2(), and STRERR_FILE_LINE.
Referenced by OmniEvents::Daemon::daemonize().
void OmniEvents::DaemonImpl::foreground | ( | bool | val | ) |
Set _foreground.
Definition at line 137 of file daemon_unix.cc.
Referenced by OmniEvents::Daemon::foreground().
|
private |
Performs the actual fork.
Definition at line 378 of file daemon_unix.cc.
References PIPE_READ, PIPE_WRITE, and STRERR_FILE_LINE.
void OmniEvents::DaemonImpl::initialize | ( | int & | , |
char **& | |||
) |
Does nothing on Unix.
Definition at line 152 of file daemon_unix.cc.
|
static |
Callback, used as a parameter to omniORB::setLogFunction().
WARNING: Performs magic! Sets the syslog priority to LOG_INFO or LOG_ERR depending upon whether the message string starts with 'omniEvents! ' or 'omniEvents: '.
Definition at line 265 of file daemon_unix.cc.
References _haveParent, and OmniEvents::daemon.
|
private |
Tells the parent to exit with the given status (Unix).
Definition at line 477 of file daemon_unix.cc.
References PIPE_WRITE, and STRERR_FILE_LINE.
|
private |
Opens a (new?) file called 'filename' for writing, and uses it to hijack stream 'fd'.
Definition at line 446 of file daemon_unix.cc.
void OmniEvents::DaemonImpl::pidfile | ( | const char * | val | ) |
Set _pidfile.
Definition at line 143 of file daemon_unix.cc.
Referenced by OmniEvents::Daemon::pidfile().
|
private |
Redirect stdout & stderr to filename.
Also redirects stdin from /dev/null
Definition at line 426 of file daemon_unix.cc.
References STDIN_FILENO, STDOUT_FILENO, and STRERR_FILE_LINE.
void OmniEvents::DaemonImpl::runningOk | ( | ) |
Called to signal that all startup operations have completed OK.
Notifies the parent process and redirects stdout & stderr to 'tracefile' (or else /dev/null).
Definition at line 215 of file daemon_unix.cc.
References PACKAGE_NAME.
Referenced by OmniEvents::Daemon::runningOk().
void OmniEvents::DaemonImpl::shutdown | ( | int | status | ) |
Exit handler called (indirectly) by ::on_exit() - shuts down the daemon.
Deletes pidfile (if we have one), notifies the parent (if we have one).
Definition at line 236 of file daemon_unix.cc.
References STRERR_FILE_LINE.
Referenced by OmniEvents::shutdown0(), OmniEvents::shutdown2(), and OmniEvents::Daemon::~Daemon().
void OmniEvents::DaemonImpl::tracefile | ( | const char * | val | ) |
Set _tracefile.
Definition at line 131 of file daemon_unix.cc.
Referenced by OmniEvents::Daemon::tracefile().
|
private |
Called by the parent process (Unix).
Waits for the child to return an exit status. The status is usually '0' - indicating that the daemon has started successfully.
Definition at line 460 of file daemon_unix.cc.
References PIPE_READ, and STRERR_FILE_LINE.
|
private |
Definition at line 353 of file daemon_unix.cc.
bool OmniEvents::DaemonImpl::_foreground |
TRUE for debug mode (run in foreground)
Definition at line 43 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon().
bool OmniEvents::DaemonImpl::_haveParent |
Is there a parent for us to clean up?
Definition at line 47 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), and log().
bool OmniEvents::DaemonImpl::_havePidfile |
Is there a pidfile for us to clean up?
Definition at line 46 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon().
bool OmniEvents::DaemonImpl::_haveSyslog |
Should we close syslog before quitting?
Definition at line 48 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon().
|
static |
Definition at line 40 of file daemon_unix.h.
char* OmniEvents::DaemonImpl::_pidfile |
The pidfile name (if any).
Definition at line 44 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon().
int OmniEvents::DaemonImpl::_pipe[2] |
Unnamed pipe for child->parent comms.
Definition at line 45 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon().
char* OmniEvents::DaemonImpl::_tracefile |
The tracefile name (if any).
Definition at line 42 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon().