E-MailRelay
|
A class for creating pid files. More...
#include <gpidfile.h>
Public Member Functions | |
PidFile (const Path &pid_file_path) | |
Constructor. More... | |
PidFile () | |
Default constructor. More... | |
~PidFile () | |
Destructor. Calls cleanup() to delete the file. More... | |
void | mkdir () |
Creates the directory if it does not already exist. More... | |
void | commit () |
Creates the pid file if a path has been defined. More... | |
bool | committed () const |
Returns true if commit() has been called with a valid path(). More... | |
Path | path () const |
Returns the full path of the file. More... | |
PidFile (const PidFile &)=delete | |
PidFile (PidFile &&)=delete | |
PidFile & | operator= (const PidFile &)=delete |
PidFile & | operator= (PidFile &&)=delete |
Static Public Member Functions | |
static bool | cleanup (SignalSafe, const char *path) noexcept |
Deletes the specified pid file if it contains this process's id. More... | |
A class for creating pid files.
Works with G::Root and G::Daemon so that the pid file can get created very late in a daemon startup sequence. Installs a signal handler so that the pid file gets deleted on process termination.
Usage:
Definition at line 56 of file gpidfile.h.
|
explicit |
Constructor.
A relative path is converted to an absolute path using the cwd. Use commit() to actually create the file.
Definition at line 38 of file gpidfile.cpp.
|
default |
Default constructor.
Constructs a do-nothing object.
G::PidFile::~PidFile | ( | ) |
Destructor. Calls cleanup() to delete the file.
Definition at line 43 of file gpidfile.cpp.
|
staticnoexcept |
Deletes the specified pid file if it contains this process's id.
Claims root privilege to read and delete the pid file (see G::Root::atExit()).
This is not normally needed by client code since it is installed as a signal handler (see G::Cleanup) and called from the destructor.
Signal-safe, reentrant implementation.
Definition at line 109 of file gpidfile.cpp.
void G::PidFile::commit | ( | ) |
Creates the pid file if a path has been defined.
Also installs signal handlers to cleanup() the file on abnormal process termination. Throws on error.
The caller should switch effective user-id and umask as necessary.
Definition at line 129 of file gpidfile.cpp.
bool G::PidFile::committed | ( | ) | const |
Returns true if commit() has been called with a valid path().
Definition at line 138 of file gpidfile.cpp.
void G::PidFile::mkdir | ( | ) |
Creates the directory if it does not already exist.
The caller should switch effective user-id and umask as necessary.
Definition at line 56 of file gpidfile.cpp.
G::Path G::PidFile::path | ( | ) | const |
Returns the full path of the file.
Definition at line 143 of file gpidfile.cpp.