24 std::ifstream fs(filename_.c_str());
46 if (kill(pid, 0) == 0) {
61 std::ofstream fs(filename_.c_str(), std::ofstream::trunc);
65 << filename_ <<
"' for write");
69 fs << pid << std::endl;
71 bool good = fs.good();
82 if ((remove(filename_.c_str()) != 0) &&
90 : lockname_(lockname), fd_(-1), locked_(false) {
92 fd_ = open(lockname_.c_str(), O_RDONLY | O_CREAT, 0600);
94 if ((errno == ENOENT) && !blocking) {
99 std::string errmsg = strerror(errno);
101 << lockname_ <<
"': " << errmsg);
105 int ret = flock(fd_, LOCK_EX | (blocking ? 0 : LOCK_NB));
110 if (errno != EWOULDBLOCK) {
111 std::string errmsg = strerror(errno);
113 << lockname_ <<
"': " << errmsg);
121 static_cast<void>(flock(fd_, LOCK_UN));
123 static_cast<void>(close(fd_));
124 static_cast<void>(remove(lockname_.c_str()));
Exception thrown when an error occurs trying to read a PID from an opened file.
Exception thrown when an error occurs during PID file processing.
void write() const
Get PID of the current process and write it to the file.
void write(int) const
Write the PID to the file.
void deleteFile() const
Delete the PID file.
int check() const
Read the PID in from the file and check it.
PIDLock(const std::string &lockname, bool blocking=false)
Constructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.