41InterprocessSyncFile::do_lock(
int cmd,
short l_type) {
46 std::string lockfile_path = LOCKFILE_DIR;
48 const char*
const env = getenv(
"KEA_LOCKFILE_DIR");
53 lockfile_path +=
"/" +
task_name_ +
"_lockfile";
57 fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR,
58 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
60 if (fchmod(fd_, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) != 0) {
67 std::stringstream tmp;
72 tmp <<
"Unable to use interprocess sync lockfile ("
73 << std::strerror(errno) <<
"): " << lockfile_path;
74 std::cerr << tmp.str() << std::endl;
77 isc_throw(InterprocessSyncFileError, tmp.str());
85 lock.l_whence = SEEK_SET;
89 return (fcntl(fd_, cmd, &
lock) == 0);
98 if (do_lock(F_SETLKW, F_WRLCK)) {
112 if (do_lock(F_SETLK, F_WRLCK)) {
126 if (do_lock(F_SETLKW, F_UNLCK)) {
bool unlock()
Release the lock.
bool lock()
Acquire the lock (blocks if something else has acquired a lock on the same task name)
virtual ~InterprocessSyncFile()
Destructor.
bool tryLock()
Try to acquire a lock (doesn't block)
bool is_locked_
Is the lock taken?
const std::string task_name_
The task name.
#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.