libutil++  1.9.3
 All Classes Functions Variables
PidFile.h
1 /*
2 ** libutil++
3 ** $Id: PidFile.h 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__util__PidFile_H__
10 #define __libutilxx__sella__util__PidFile_H__
11 
12 #include "../../common.h"
13 #include "PidFileException.h"
14 
15 #include <unistd.h>
16 #include <sys/types.h>
17 
18 #include <string>
19 #include <memory>
20 
21 namespace sella {
22  namespace util {
23  class PidFile;
24  }
25 }
26 
28  public:
29  typedef std::shared_ptr<PidFile> shared;
30  typedef PidFile* ptr;
31 
32  public:
33  PidFile(const std::string &file, uid_t uid = -1, gid_t gid = -1) throw ();
34  PidFile(const PidFile &other);
35  virtual ~PidFile();
36 
37  PidFile& operator=(const PidFile &other) throw ();
38  bool operator==(const PidFile &other) const throw () = delete;
39  bool operator!=(const PidFile &other) const throw () = delete;
40 
41  const std::string& get(void) const throw (); /* Get filename */
42  int read(void) const throw (PidFileException); /* Read pid from file */
43  int write(void) const throw (PidFileException); /* Write pid to file */
44  void remove(void) const throw (PidFileException); /* Remove file */
45 
46  bool isOwner(void) const throw (); /* Check if we're the file owner */
47  bool isLive(void) const throw (); /* Check if the file owner is live/running */
48  bool isFile(void) const throw (); /* Check if there is a file */
49 
50  static const PidFile::shared shared_ptr(const std::string &file, uid_t uid = -1, gid_t gid = -1) throw ();
51 
52  private:
53  std::string file;
54  uid_t uid;
55  gid_t gid;
56 };
57 
58 #endif
59 
60 /*
61 ** vim: noet ts=3 sw=3
62 */