Kea  1.9.9-git
pid_file.h
Go to the documentation of this file.
1 // Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef PID_FILE_H
8 #define PID_FILE_H
9 
10 #include <exceptions/exceptions.h>
11 #include <boost/shared_ptr.hpp>
12 #include <fstream>
13 #include <ostream>
14 #include <string>
15 
16 namespace isc {
17 namespace util {
18 
20 class PIDFileError : public Exception {
21 public:
22  PIDFileError(const char* file, size_t line, const char* what) :
23  isc::Exception(file, line, what) { };
24 };
25 
28 class PIDCantReadPID : public Exception {
29 public:
30  PIDCantReadPID(const char* file, size_t line, const char* what) :
31  isc::Exception(file, line, what) { };
32 };
33 
40 class PIDFile {
41 public:
45  PIDFile(const std::string& filename);
46 
48  ~PIDFile();
49 
62  int check() const;
63 
69  void write(int) const;
70 
74  void write() const;
75 
79  void deleteFile() const;
80 
82  std::string getFilename() const {
83  return (filename_);
84  }
85 
86 private:
88  std::string filename_;
89 };
90 
92 typedef boost::shared_ptr<PIDFile> PIDFilePtr;
93 
94 } // namespace isc::util
95 } // namespace isc
96 
97 #endif // PID_FILE_H
void deleteFile() const
Delete the PID file.
Definition: pid_file.cc:84
int check() const
Read the PID in from the file and check it.
Definition: pid_file.cc:26
PIDCantReadPID(const char *file, size_t line, const char *what)
Definition: pid_file.h:30
Exception thrown when an error occurs during PID file processing.
Definition: pid_file.h:20
Class to help with processing PID files.
Definition: pid_file.h:40
void write() const
Get PID of the current process and write it to the file.
Definition: pid_file.cc:58
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string getFilename() const
Returns the path to the PID file.
Definition: pid_file.h:82
boost::shared_ptr< PIDFile > PIDFilePtr
Defines a shared pointer to a PIDFile.
Definition: pid_file.h:92
PIDFile(const std::string &filename)
Constructor.
Definition: pid_file.cc:18
PIDFileError(const char *file, size_t line, const char *what)
Definition: pid_file.h:22
~PIDFile()
Destructor.
Definition: pid_file.cc:22
Exception thrown when an error occurs trying to read a PID from an opened file.
Definition: pid_file.h:28