Skip to main content

guard

Function guard 

Source
pub fn guard(name: &str) -> Result<Guard>
Available on crate feature guard only.
Expand description

Starts the process guard with secure defaults: a single-instance lock in path-lib’s runtime directory for name, umask(0o027), and the soft open-file limit raised to 65 536 (at least 1 024 required). Call it before any file is opened and before threads start, and keep the Guard for the life of the process.

use sys_lib as sys;

let guard = sys::process::guard("site")?;      // before any file is opened
println!("lock {:?}", guard.lock_file());
// ... run; the lock is held while `guard` lives.

§Errors

Error::AlreadyRunning when another copy holds the lock, Error::RunDirUnavailable when the lock directory cannot be created or trusted, Error::OpenFilesTooLow when the hard open-file limit is below the minimum, and Error::InvalidInput for an invalid name.