E-MailRelay
Public Member Functions | List of all members
G::PidFile Class Reference

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. Deletes 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
 
PidFileoperator= (const PidFile &)=delete
 
PidFileoperator= (PidFile &&)=delete
 

Detailed Description

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:

G::Root::init("nobody") ;
G::PidFile pid_file( path ) ;
{ G::Root _ ; pid_file.mkdir() ; }
if( daemon ) G::Daemon::detach( pid_file.path() ) ;
{ G::Root _ ; pid_file.commit() ; }
static void detach()
Detaches from the parent environment.
A class for creating pid files.
Definition: gpidfile.h:56
Path path() const
Returns the full path of the file.
Definition: gpidfile.cpp:109
A class which acquires the process's special privileges on construction and releases them on destruct...
Definition: groot.h:52
static void init(const std::string &nobody, bool fixed_group=false)
< Destructor.
Definition: groot.cpp:80
See also
G::Daemon

Definition at line 55 of file gpidfile.h.

Constructor & Destructor Documentation

◆ PidFile() [1/2]

G::PidFile::PidFile ( const Path pid_file_path)
explicit

Constructor.

A relative path is converted to an absolute path using the cwd. Use commit() to actually create the file.

Definition at line 47 of file gpidfile.cpp.

◆ PidFile() [2/2]

G::PidFile::PidFile ( )
default

Default constructor.

Constructs a do-nothing object.

◆ ~PidFile()

G::PidFile::~PidFile ( )

Destructor. Deletes the file.

Definition at line 52 of file gpidfile.cpp.

Member Function Documentation

◆ commit()

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 95 of file gpidfile.cpp.

◆ committed()

bool G::PidFile::committed ( ) const

Returns true if commit() has been called with a valid path().

Definition at line 104 of file gpidfile.cpp.

◆ mkdir()

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 69 of file gpidfile.cpp.

◆ path()

G::Path G::PidFile::path ( ) const

Returns the full path of the file.

Definition at line 109 of file gpidfile.cpp.


The documentation for this class was generated from the following files: