diff options
Diffstat (limited to 'crates/runner/src/util/unix.rs')
-rw-r--r-- | crates/runner/src/util/unix.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/crates/runner/src/util/unix.rs b/crates/runner/src/util/unix.rs index 156e441..08884ec 100644 --- a/crates/runner/src/util/unix.rs +++ b/crates/runner/src/util/unix.rs @@ -1,7 +1,7 @@ use std::{fs::File, os::unix::prelude::*, path::Path}; use nix::{ - fcntl::{self, FcntlArg, FdFlag, OFlag}, + fcntl::{self, FcntlArg, FdFlag, Flock, OFlag}, sched, unistd::Pid, }; @@ -65,7 +65,7 @@ pub fn nproc() -> Result<usize> { Ok(count) } -pub fn lock<P: AsRef<Path>>(path: P, exclusive: bool, blocking: bool) -> Result<File> { +pub fn lock<P: AsRef<Path>>(path: P, exclusive: bool, blocking: bool) -> Result<Flock<File>> { use fcntl::FlockArg::*; if let Some(parent) = path.as_ref().parent() { @@ -80,8 +80,7 @@ pub fn lock<P: AsRef<Path>>(path: P, exclusive: bool, blocking: bool) -> Result< }; let file = fs::create(path.as_ref())?; - fcntl::flock(file.as_raw_fd(), arg) - .with_context(|| format!("flock failed on {:?}", path.as_ref()))?; - - Ok(file) + fcntl::Flock::lock(file, arg) + .map_err(|(_, errno)| errno) + .with_context(|| format!("flock failed on {:?}", path.as_ref())) } |