Skip to content
API Documentation
BastionGuard™
InstanceLock Class Reference

Public Member Functions

 InstanceLock (const char *path)
bool acquired () const
 ~InstanceLock ()

Private Attributes

int fd_
std::string path_

Detailed Description

Definition at line 98 of file SecureBrowser.cpp.

Constructor & Destructor Documentation

◆ InstanceLock()

InstanceLock::InstanceLock ( const char * path)
inlineexplicit

Definition at line 100 of file SecureBrowser.cpp.

100 : fd_(-1), path_(path) {
101 fd_ = ::open(path, O_CREAT | O_RDWR, 0600);
102 if (fd_ >= 0) {
103 if (flock(fd_, LOCK_EX | LOCK_NB) != 0) {
104 ::close(fd_);
105 fd_ = -1;
106 } else {
107 ftruncate(fd_, 0);
108 std::string pid = std::to_string(getpid());
109 ::write(fd_, pid.c_str(), pid.size());
110 ::fsync(fd_);
111 }
112 }
113 }
std::string path_

References fd_, and path_.

◆ ~InstanceLock()

InstanceLock::~InstanceLock ( )
inline

Definition at line 117 of file SecureBrowser.cpp.

117 {
118 if (fd_ >= 0) {
119 flock(fd_, LOCK_UN);
120 ::close(fd_);
121 }
122 }

References fd_.

Member Function Documentation

◆ acquired()

bool InstanceLock::acquired ( ) const
inline

Definition at line 115 of file SecureBrowser.cpp.

115{ return fd_ >= 0; }

References fd_.

Referenced by SecureBrowser::open(), and SecureBrowser::open_notify().

Member Data Documentation

◆ fd_

int InstanceLock::fd_
private

Definition at line 125 of file SecureBrowser.cpp.

Referenced by acquired(), InstanceLock(), and ~InstanceLock().

◆ path_

std::string InstanceLock::path_
private

Definition at line 126 of file SecureBrowser.cpp.

Referenced by InstanceLock().


The documentation for this class was generated from the following file: