38 cleanup(
SignalSafe() , m_path.str().c_str() ) ;
51 void G::PidFile::create(
const Path & pid_file )
53 if( pid_file !=
Path() )
55 G_DEBUG(
"G::PidFile::create: \"" << pid_file <<
"\"" ) ;
58 std::ofstream file( pid_file.
str().c_str() ) ;
60 file << pid.
str() << std::endl ;
62 throw Error(std::string(
"cannot create file: ")+pid_file.
str()) ;
67 bool G::PidFile::mine( SignalSafe safe ,
const char * path )
70 Process::Id this_pid ;
71 Process::Id file_pid( safe , path ) ;
72 return this_pid == file_pid ;
81 if( path && *path && mine(safe,path) )
94 if( valid() && ! m_path.isAbsolute() )
95 throw Error(std::string(
"must be an absolute path: ")+m_path.str()) ;
109 bool G::PidFile::valid()
const
111 return m_path !=
Path() ;
void init(const Path &pid_file_path)
Used after default construction.
std::string str() const
Returns the path string.
void check()
Throws an exception if the path is not absolute.
An empty structure that is used to indicate a signal-safe, reentrant implementation.
Path path() const
Returns the path as supplied to the constructor or init().
A very low-level interface to getpwnam() and the get/set/e/uid/gid functions.
static Identity start(SignalSafe)
A signal-safe alternative to construction.
Used to temporarily modify the process umask.
static void stop(SignalSafe, Identity)
A signal-safe alternative to destruction.
PidFile()
Default constructor.
static void cleanup(SignalSafe, const char *path)
Deletes the specified pid file if it contains this process's id.
void commit()
Creates the file.
A Path object represents a file system path.
static void add(void(*fn)(SignalSafe, const char *), const char *arg)
Adds the given handler to the list which are to be called when the process terminates abnormally...