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. | |
| void | pidfile (const char *val) |
| Set _pidfile. | |
| void | foreground (bool val) |
| Set _foreground. | |
| void | initialize (int &, char **&) |
| Does nothing on Unix. | |
| void | daemonize () |
| Puts the current process into the background. | |
| void | runningOk () |
| Called to signal that all startup operations have completed OK. | |
| void | shutdown (int status) |
| Exit handler called (indirectly) by on_exit() - shuts down the daemon. | |
Static Public Member Functions | |
| static void | log (const char *message) |
| Callback, used as a parameter to omniORB::setLogFunction(). | |
Public Attributes | |
| char * | _tracefile |
| The tracefile name (if any). | |
| bool | _foreground |
| TRUE for debug mode (run in foreground). | |
| char * | _pidfile |
| The pidfile name (if any). | |
| int | _pipe [2] |
| Unnamed pipe for child->parent comms. | |
| bool | _havePidfile |
| Is there a pidfile for us to clean up? | |
| bool | _haveParent |
| Is there a parent for us to clean up? | |
| bool | _haveSyslog |
| Should we close syslog before quitting? | |
Static Public Attributes | |
| static DaemonImpl | _inst |
Private Member Functions | |
| void | fork () |
| Performs the actual fork. | |
| void | redirectStreamsTo (const char *filename) |
| Redirect stdout & stderr to filename. | |
| int | openFileFor (int fd, const char *filename, int flags) |
| Opens a (new?) file called 'filename' for writing, and uses it to hijack stream 'fd'. | |
| void | checkPidfileOrShutdown () |
| If pidfile exists & contains a running process then shutdown() (Unix). | |
| void | writePidfile () |
| int | waitForChild () |
| Called by the parent process (Unix). | |
| void | notifyParent (int status) |
| Tells the parent to exit with the given status (Unix). | |
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.
References _pidfile, and _tracefile.
| void OmniEvents::DaemonImpl::checkPidfileOrShutdown | ( | ) | [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 _pidfile, and STRERR_FILE_LINE.
Referenced by daemonize().
| 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 _foreground, _haveSyslog, _tracefile, checkPidfileOrShutdown(), fork(), log(), PACKAGE_NAME, redirectStreamsTo(), omniORB::setLogFunction(), OmniEvents::shutdown0(), OmniEvents::shutdown2(), STRERR_FILE_LINE, and writePidfile().
Referenced by OmniEvents::Daemon::daemonize().
| void OmniEvents::DaemonImpl::foreground | ( | bool | val | ) |
Set _foreground.
Definition at line 137 of file daemon_unix.cc.
References _foreground.
Referenced by OmniEvents::Daemon::foreground().
| void OmniEvents::DaemonImpl::fork | ( | ) | [private] |
Performs the actual fork.
Definition at line 378 of file daemon_unix.cc.
References _haveParent, _pipe, PIPE_READ, PIPE_WRITE, STRERR_FILE_LINE, and waitForChild().
Referenced by daemonize().
| void OmniEvents::DaemonImpl::initialize | ( | int & | , | |
| char **& | ||||
| ) |
Does nothing on Unix.
Definition at line 152 of file daemon_unix.cc.
| void OmniEvents::DaemonImpl::log | ( | const char * | message | ) | [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.
Referenced by daemonize().
| void OmniEvents::DaemonImpl::notifyParent | ( | int | status | ) | [private] |
Tells the parent to exit with the given status (Unix).
Definition at line 477 of file daemon_unix.cc.
References _pipe, PIPE_WRITE, and STRERR_FILE_LINE.
Referenced by runningOk(), and shutdown().
| int OmniEvents::DaemonImpl::openFileFor | ( | int | fd, | |
| const char * | filename, | |||
| int | flags | |||
| ) | [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.
Referenced by redirectStreamsTo().
| void OmniEvents::DaemonImpl::pidfile | ( | const char * | val | ) |
Set _pidfile.
Definition at line 143 of file daemon_unix.cc.
References _pidfile.
Referenced by OmniEvents::Daemon::pidfile().
| void OmniEvents::DaemonImpl::redirectStreamsTo | ( | const char * | filename | ) | [private] |
Redirect stdout & stderr to filename.
Also redirects stdin from /dev/null
Definition at line 426 of file daemon_unix.cc.
References openFileFor(), STDIN_FILENO, STDOUT_FILENO, and STRERR_FILE_LINE.
Referenced by daemonize(), and runningOk().
| 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 _haveParent, _haveSyslog, notifyParent(), PACKAGE_NAME, and redirectStreamsTo().
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 _haveParent, _havePidfile, _haveSyslog, _pidfile, notifyParent(), and STRERR_FILE_LINE.
Referenced by OmniEvents::shutdown2(), and OmniEvents::Daemon::~Daemon().
| void OmniEvents::DaemonImpl::tracefile | ( | const char * | val | ) |
Set _tracefile.
Definition at line 131 of file daemon_unix.cc.
References _tracefile.
Referenced by OmniEvents::Daemon::tracefile().
| int OmniEvents::DaemonImpl::waitForChild | ( | ) | [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, PIPE_READ, and STRERR_FILE_LINE.
Referenced by fork().
| void OmniEvents::DaemonImpl::writePidfile | ( | ) | [private] |
Definition at line 353 of file daemon_unix.cc.
References _havePidfile, and _pidfile.
Referenced by daemonize().
TRUE for debug mode (run in foreground).
Definition at line 43 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), daemonize(), and foreground().
Is there a parent for us to clean up?
Definition at line 47 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), fork(), log(), runningOk(), and shutdown().
Is there a pidfile for us to clean up?
Definition at line 46 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), shutdown(), and writePidfile().
Should we close syslog before quitting?
Definition at line 48 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), daemonize(), runningOk(), and shutdown().
DaemonImpl OmniEvents::DaemonImpl::_inst [static] |
Definition at line 40 of file daemon_unix.h.
The pidfile name (if any).
Definition at line 44 of file daemon_unix.h.
Referenced by checkPidfileOrShutdown(), OmniEvents::Daemon::Daemon(), pidfile(), shutdown(), writePidfile(), and ~DaemonImpl().
Unnamed pipe for child->parent comms.
Definition at line 45 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), fork(), notifyParent(), and waitForChild().
The tracefile name (if any).
Definition at line 42 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), daemonize(), tracefile(), and ~DaemonImpl().
1.6.1