pub struct PidFile { /* private fields */ }Expand description
RAII handle for a pidfile we currently own. Releases on Drop.
Dropping removes the file only if its contents still match our pid — so a second daemon that stole the lock (e.g. after we crashed) doesn’t get its pidfile deleted out from under it when we eventually unwind.
Implementations§
Source§impl PidFile
impl PidFile
Sourcepub fn acquire(path: impl Into<PathBuf>) -> Result<Self, LockError>
pub fn acquire(path: impl Into<PathBuf>) -> Result<Self, LockError>
Try to take the pidfile at path. On success, our pid is written
to disk and held until drop.
If a previous pidfile exists and that pid is still alive,
Err(LockError::HeldBy) is returned and the file is left untouched.
A stale pidfile (dead pid) is silently replaced.
pub fn path(&self) -> &Path
pub fn pid(&self) -> u32
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PidFile
impl RefUnwindSafe for PidFile
impl Send for PidFile
impl Sync for PidFile
impl Unpin for PidFile
impl UnsafeUnpin for PidFile
impl UnwindSafe for PidFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more