From 89e193c1ab8184f74b2b40f3822e544d5e0d5163 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 2 Apr 2024 22:40:59 +0200 Subject: Update dependencies --- crates/driver/Cargo.toml | 4 ++-- crates/driver/src/driver.rs | 4 ++-- crates/runner/Cargo.toml | 2 +- crates/runner/src/jobserver.rs | 15 ++++++--------- crates/runner/src/lib.rs | 15 +++++++++++---- crates/runner/src/util/fs.rs | 2 +- crates/runner/src/util/unix.rs | 11 +++++------ 7 files changed, 28 insertions(+), 25 deletions(-) (limited to 'crates') diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index ecea8b8..683ebbe 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -14,10 +14,10 @@ runner = { path = "../runner", package = "rebel-runner" } clap = { version = "4.0.0", features = ["derive"] } deb-version = "0.1.1" enum-kinds = "0.5.1" -handlebars = "4.1.3" +handlebars = "5.1.2" indoc = "2.0.4" lazy_static = "1.4.0" -nix = { version = "0.27.1", features = ["poll"] } +nix = { version = "0.28.0", features = ["poll"] } nom = "7.1.0" scoped-tls-hkt = "0.1.2" serde = { version = "1", features = ["derive", "rc"] } diff --git a/crates/driver/src/driver.rs b/crates/driver/src/driver.rs index d0abbcb..8acf50a 100644 --- a/crates/driver/src/driver.rs +++ b/crates/driver/src/driver.rs @@ -352,10 +352,10 @@ impl<'ctx> Driver<'ctx> { let mut pollfds: Vec<_> = self .tasks_running .values() - .map(|(socket, _)| poll::PollFd::new(socket, poll::PollFlags::POLLIN)) + .map(|(socket, _)| poll::PollFd::new(socket.as_fd(), poll::PollFlags::POLLIN)) .collect(); - while poll::poll(&mut pollfds, -1).context("poll()")? == 0 {} + while poll::poll(&mut pollfds, poll::PollTimeout::NONE).context("poll()")? == 0 {} let pollevents: Vec<_> = pollfds .into_iter() diff --git a/crates/runner/Cargo.toml b/crates/runner/Cargo.toml index bd1287e..ed2716b 100644 --- a/crates/runner/Cargo.toml +++ b/crates/runner/Cargo.toml @@ -15,7 +15,7 @@ blake3 = { version = "1.3.0", features = ["traits-preview"] } capctl = "0.2.0" digest = "0.10.1" libc = "0.2.84" -nix = { version = "0.27.1", features = ["user", "fs", "process", "mount", "sched", "poll", "signal", "hostname"] } +nix = { version = "0.28.0", features = ["user", "fs", "process", "mount", "sched", "poll", "signal", "hostname"] } olpc-cjson = "0.1.0" serde = { version = "1", features = ["derive"] } serde_json = "1.0.62" diff --git a/crates/runner/src/jobserver.rs b/crates/runner/src/jobserver.rs index 2422a75..b0b88cd 100644 --- a/crates/runner/src/jobserver.rs +++ b/crates/runner/src/jobserver.rs @@ -1,5 +1,5 @@ use std::{ - os::fd::{AsRawFd, FromRawFd, OwnedFd}, + os::fd::{AsFd, AsRawFd, OwnedFd}, slice, }; @@ -18,13 +18,10 @@ pub struct Jobserver { impl Jobserver { pub fn new(tokens: usize) -> Result { - let (piper, pipew) = - unistd::pipe2(OFlag::O_CLOEXEC | OFlag::O_NONBLOCK).context("pipe()")?; - let r = unsafe { OwnedFd::from_raw_fd(piper) }; - let w = unsafe { OwnedFd::from_raw_fd(pipew) }; + let (r, w) = unistd::pipe2(OFlag::O_CLOEXEC | OFlag::O_NONBLOCK).context("pipe()")?; for _ in 0..tokens { - if unistd::write(w.as_raw_fd(), b"+").is_err() { + if unistd::write(w.as_fd(), b"+").is_err() { break; } } @@ -36,8 +33,8 @@ impl Jobserver { pub fn wait(&mut self) -> u8 { loop { poll::poll( - &mut [poll::PollFd::new(&self.r, poll::PollFlags::POLLIN)], - -1, + &mut [poll::PollFd::new(self.r.as_fd(), poll::PollFlags::POLLIN)], + poll::PollTimeout::NONE, ) .expect("poll()"); @@ -59,7 +56,7 @@ impl Jobserver { } pub fn post(&mut self, token: u8) { - let n = unistd::write(self.w.as_raw_fd(), slice::from_ref(&token)).expect("write()"); + let n = unistd::write(self.w.as_fd(), slice::from_ref(&token)).expect("write()"); assert!(n == 1); } diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index 308b54c..bcaa9db 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -17,6 +17,7 @@ use std::{ use capctl::prctl; use nix::{ errno::Errno, + fcntl::Flock, poll, sched::CloneFlags, sys::{ @@ -99,7 +100,13 @@ fn borrow_socket_fd(socket: &UnixSeqpacketConn) -> BorrowedFd<'_> { unsafe { BorrowedFd::borrow_raw(socket.as_raw_fd()) } } -fn runner(uid: Uid, gid: Gid, socket: UnixSeqpacketConn, _lockfile: File, options: &Options) -> ! { +fn runner( + uid: Uid, + gid: Gid, + socket: UnixSeqpacketConn, + _lockfile: Flock, + options: &Options, +) -> ! { ns::mount_proc(); ns::setup_userns(Uid::from_raw(0), Gid::from_raw(0), uid, gid); @@ -127,10 +134,10 @@ fn runner(uid: Uid, gid: Gid, socket: UnixSeqpacketConn, _lockfile: File, option loop { let socket_fd = borrow_socket_fd(&ctx.socket); let mut pollfds = [ - poll::PollFd::new(&signal_fd, poll::PollFlags::POLLIN), - poll::PollFd::new(&socket_fd, poll::PollFlags::POLLIN), + poll::PollFd::new(signal_fd.as_fd(), poll::PollFlags::POLLIN), + poll::PollFd::new(socket_fd.as_fd(), poll::PollFlags::POLLIN), ]; - poll::poll(&mut pollfds, -1).expect("poll()"); + poll::poll(&mut pollfds, poll::PollTimeout::NONE).expect("poll()"); let signal_events = pollfds[0] .revents() 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, P2: AsRef>( 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 { Ok(count) } -pub fn lock>(path: P, exclusive: bool, blocking: bool) -> Result { +pub fn lock>(path: P, exclusive: bool, blocking: bool) -> Result> { use fcntl::FlockArg::*; if let Some(parent) = path.as_ref().parent() { @@ -80,8 +80,7 @@ pub fn lock>(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())) } -- cgit v1.2.3