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 <<
"\"" ) ;
60 file.open( pid_file.
str().c_str() , std::ios_base::out | std::ios_base::trunc ) ;
63 file << pid.str() << std::endl ;
66 throw Error(std::string(
"cannot create file: ")+pid_file.
str()) ;
71 bool G::PidFile::mine( SignalSafe safe ,
const char * path )
74 Process::Id this_pid ;
75 Process::Id file_pid( safe , path ) ;
76 return this_pid == file_pid ;
85 if( path && *path && mine(safe,path) )
96 if( valid() && ! m_path.isAbsolute() )
97 throw Error(std::string(
"must be an absolute path: ")+m_path.str()) ;
111 bool G::PidFile::valid()
const
113 return m_path !=
Path() ;
void init(const Path &pid_file_path)
Used after default construction to make the object active.
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 combination of user-id and group-id, with a very low-level interface to the get/set/e/uid/gid funct...
~PidFile()
Destructor. Calls cleanup() to delete the file.
static Identity start(SignalSafe)
A signal-safe alternative to construction.
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 and installs signal handlers to cleanup() the file on abnormal process termination...
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 of handlers that are to be called when the process terminates abno...