summaryrefslogtreecommitdiffstats
path: root/crates/runner/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'crates/runner/src/util')
-rw-r--r--crates/runner/src/util/fs.rs2
-rw-r--r--crates/runner/src/util/unix.rs11
2 files changed, 6 insertions, 7 deletions
diff --git a/crates/runner/src/util/fs.rs b/crates/runner/src/util/fs.rs
index 9e16648..5efd159 100644
--- a/crates/runner/src/util/fs.rs
+++ b/crates/runner/src/util/fs.rs
@@ -123,5 +123,5 @@ pub fn mount<P1: AsRef<Path>, P2: AsRef<Path>>(
pub fn pipe() -> Result<(File, File)> {
unistd::pipe2(OFlag::O_CLOEXEC)
.context("pipe2()")
- .map(|(piper, pipew)| unsafe { (File::from_raw_fd(piper), File::from_raw_fd(pipew)) })
+ .map(|(piper, pipew)| (File::from(piper), File::from(pipew)))
}
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()))
}