sbuild
1.6.0
|
Device lock. More...
#include <sbuild-lock.h>
Public Member Functions | |
device_lock (std::string const &device) | |
The constructor. | |
virtual | ~device_lock () |
The destructor. | |
virtual void | set_lock (lock::type lock_type, unsigned int timeout) |
Acquire a lock. | |
virtual void | unset_lock () |
Release a lock. |
Private Attributes | |
std::string | device |
The device to lock. | |
bool | locked |
Is the file locked? |
Additional Inherited Members | |
![]() | |
enum | type { LOCK_SHARED = F_RDLCK, LOCK_EXCLUSIVE = F_WRLCK, LOCK_NONE = F_UNLCK } |
Lock type. More... | |
enum | error_code { TIMEOUT_HANDLER, TIMEOUT_SET, TIMEOUT_CANCEL, LOCK, UNLOCK, LOCK_TIMEOUT, UNLOCK_TIMEOUT, DEVICE_LOCK, DEVICE_LOCK_TIMEOUT, DEVICE_TEST, DEVICE_UNLOCK, DEVICE_UNLOCK_TIMEOUT } |
Error codes. More... | |
typedef custom_error< error_code > | error |
Exception type. | |
![]() | |
lock () | |
The constructor. | |
virtual | ~lock () |
The destructor. | |
void | set_alarm () |
Set the SIGALARM handler. | |
void | clear_alarm () |
Restore the state of SIGALRM prior to starting lock acquisition. | |
void | set_timer (struct itimerval const &timer) |
Set up an itimer for future expiry. | |
void | unset_timer () |
Remove any itimer currently set up. |
Device lock.
Set an advisory lock on a device. The lock is acquired using liblockdev lock_dev(). Note that a lock_type of LOCK_SHARED is equivalent to LOCK_EXCLUSIVE, because this lock type does not support shared locks.
device_lock::device_lock | ( | std::string const & | device | ) |
The constructor.
device | the device to lock (full pathname). |
|
virtual |
Acquire a lock.
lock_type | the type of lock to acquire. |
timeout | the time in seconds to wait on the lock. |
Implements sbuild::lock.
References device, sbuild::lock::DEVICE_LOCK, sbuild::lock::DEVICE_LOCK_TIMEOUT, sbuild::lock::DEVICE_TEST, sbuild::lock::DEVICE_UNLOCK, sbuild::lock::DEVICE_UNLOCK_TIMEOUT, sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_SHARED, locked, sbuild::lock::set_timer(), and sbuild::lock::unset_timer().
Referenced by sbuild::chroot_block_device::setup_lock(), sbuild::chroot_lvm_snapshot::setup_lock(), and unset_lock().
|
virtual |
Release a lock.
This is equivalent to set_lock with a lock_type of LOCK_NONE and a timeout of 0.
Implements sbuild::lock.
References sbuild::lock::LOCK_NONE, and set_lock().
Referenced by sbuild::chroot_block_device::setup_lock(), and sbuild::chroot_lvm_snapshot::setup_lock().