gpidfile.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20 
21 #ifndef G_PIDFILE_H
22 #define G_PIDFILE_H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include "gsignalsafe.h"
27 #include "gpath.h"
28 #include <sys/types.h>
29 #include <string>
30 
32 namespace G
33 {
34  class PidFile ;
35  class Daemon ;
36 }
37 
56 class G::PidFile
57 {
58 public:
59  G_EXCEPTION( Error , "invalid pid file" ) ;
60 
61  static void cleanup( SignalSafe , const char * path ) ;
66 
67  explicit PidFile( const Path & pid_file_path ) ;
71 
72  PidFile() ;
75 
76  void init( const Path & pid_file_path ) ;
78 
79  ~PidFile() ;
82 
83  void commit() ;
85 
86  void check() ;
89 
90  Path path() const ;
93 
94 private:
95  Path m_path ;
96 
97 private:
98  PidFile( const PidFile & ) ; // not implemented
99  void operator=( const PidFile & ) ; // not implemented
100  static bool mine( SignalSafe , const char * path ) ; // reentrant
101  static void create( const Path & pid_file ) ;
102  bool valid() const ;
103 } ;
104 
105 #endif
106 
void init(const Path &pid_file_path)
Used after default construction.
Definition: gpidfile.cpp:46
void check()
Throws an exception if the path is not absolute.
Definition: gpidfile.cpp:92
An empty structure that is used to indicate a signal-safe, reentrant implementation.
Definition: gsignalsafe.h:35
Path path() const
Returns the path as supplied to the constructor or init().
Definition: gpidfile.cpp:104
~PidFile()
Destructor.
Definition: gpidfile.cpp:35
PidFile()
Default constructor.
Definition: gpidfile.cpp:31
static void cleanup(SignalSafe, const char *path)
Deletes the specified pid file if it contains this process's id.
Definition: gpidfile.cpp:75
Low-level classes.
void commit()
Creates the file.
Definition: gpidfile.cpp:98
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
A class for creating pid files.
Definition: gpidfile.h:56
A Path object represents a file system path.
Definition: gpath.h:44