#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). |
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 | ( | ) |
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().
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::foreground | ( | bool | val | ) |
Set _foreground.
Definition at line 137 of file daemon_unix.cc.
References _foreground.
Referenced by OmniEvents::Daemon::foreground().
void OmniEvents::DaemonImpl::initialize | ( | int & | , | |
char **& | ||||
) |
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::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 214 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 235 of file daemon_unix.cc.
References _haveParent, _havePidfile, _haveSyslog, _pidfile, notifyParent(), and STRERR_FILE_LINE.
Referenced by OmniEvents::shutdown0(), OmniEvents::shutdown2(), and OmniEvents::Daemon::~Daemon().
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 264 of file daemon_unix.cc.
References _haveParent, and OmniEvents::daemon.
Referenced by daemonize().
void OmniEvents::DaemonImpl::fork | ( | ) | [private] |
Performs the actual fork.
Definition at line 377 of file daemon_unix.cc.
References _haveParent, _pipe, PIPE_READ, PIPE_WRITE, STRERR_FILE_LINE, and waitForChild().
Referenced by daemonize().
void OmniEvents::DaemonImpl::redirectStreamsTo | ( | const char * | filename | ) | [private] |
Redirect stdout & stderr to filename.
Also redirects stdin from /dev/null
Definition at line 425 of file daemon_unix.cc.
References openFileFor(), STDIN_FILENO, STDOUT_FILENO, and STRERR_FILE_LINE.
Referenced by daemonize(), and runningOk().
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 445 of file daemon_unix.cc.
Referenced by redirectStreamsTo().
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 297 of file daemon_unix.cc.
References _pidfile, and STRERR_FILE_LINE.
Referenced by daemonize().
void OmniEvents::DaemonImpl::writePidfile | ( | ) | [private] |
Definition at line 352 of file daemon_unix.cc.
References _havePidfile, and _pidfile.
Referenced by daemonize().
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 459 of file daemon_unix.cc.
References _pipe, PIPE_READ, and STRERR_FILE_LINE.
Referenced by fork().
void OmniEvents::DaemonImpl::notifyParent | ( | int | status | ) | [private] |
Tells the parent to exit with the given status (Unix).
Definition at line 476 of file daemon_unix.cc.
References _pipe, PIPE_WRITE, and STRERR_FILE_LINE.
Referenced by runningOk(), and shutdown().
DaemonImpl OmniEvents::DaemonImpl::_inst [static] |
Definition at line 40 of file daemon_unix.h.
The tracefile name (if any).
Definition at line 42 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), daemonize(), tracefile(), and ~DaemonImpl().
TRUE for debug mode (run in foreground).
Definition at line 43 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), daemonize(), and foreground().
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().
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().
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().
Should we close syslog before quitting?
Definition at line 48 of file daemon_unix.h.
Referenced by OmniEvents::Daemon::Daemon(), daemonize(), runningOk(), and shutdown().