29namespace interprocess {
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 const mode_t mode = umask(S_IXUSR | S_IXGRP | S_IXOTH);
58 fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR,
59 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
63 std::stringstream tmp;
68 tmp <<
"Unable to use interprocess sync lockfile ("
69 << std::strerror(errno) <<
"): " << lockfile_path;
70 std::cerr << tmp.str() << std::endl;
73 isc_throw(InterprocessSyncFileError, tmp.str());
81 lock.l_whence = SEEK_SET;
85 return (fcntl(fd_, cmd, &
lock) == 0);
94 if (do_lock(F_SETLKW, F_WRLCK)) {
108 if (do_lock(F_SETLK, F_WRLCK)) {
122 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.