summaryrefslogtreecommitdiffstats
path: root/crates/runner/src/util
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-02 22:40:59 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-02 22:40:59 +0200
commit89e193c1ab8184f74b2b40f3822e544d5e0d5163 (patch)
treedae862e629bd499c3d7f344ebeab938781e913a6 /crates/runner/src/util
parent1e8875b6437f3b3a1505e25dde8e352d232b09fa (diff)
downloadrebel-89e193c1ab8184f74b2b40f3822e544d5e0d5163.tar
rebel-89e193c1ab8184f74b2b40f3822e544d5e0d5163.zip
Update dependencies
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()))
}