pub struct ProgramLock { /* private fields */ }Expand description
Manages a lock file used to track if an iroh program is already running. Aquired locks write a file to iroh’s application data path containing the process identifier (PID) of the process with the lock. The lock exclusion test requires both a lockfile AND a running process listed at the PID in the file An acquired lock is released either when the object is dropped or when the program stops, which removes the file Invalid or corrupt locks are overwritten on acquisition
Implementations§
Source§impl ProgramLock
impl ProgramLock
Sourcepub fn new(prog_name: &str) -> Result<Self>
pub fn new(prog_name: &str) -> Result<Self>
Create a new lock for the given program. This does not yet acquire the lock.
Sourcepub fn acquire_or_exit(&mut self) -> &mut Self
pub fn acquire_or_exit(&mut self) -> &mut Self
Shorthand intended for main functions that need a lock to guard the process
pub fn path(&self) -> &PathBuf
pub fn program_name(&self) -> &str
Sourcepub fn active_pid(&mut self) -> Result<Pid>
pub fn active_pid(&mut self) -> Result<Pid>
returns the PID in the lockfile only if the process is active
pub fn destroy_without_checking(&self) -> Result<()>
Trait Implementations§
Source§impl Debug for ProgramLock
impl Debug for ProgramLock
Auto Trait Implementations§
impl Freeze for ProgramLock
impl RefUnwindSafe for ProgramLock
impl Send for ProgramLock
impl Sync for ProgramLock
impl Unpin for ProgramLock
impl UnwindSafe for ProgramLock
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more