From 7dab1b39947d93233d147893c553968d3bc45327 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 28 Sep 2025 10:56:13 +0100 Subject: [PATCH] Use libc::dup2 and libc::read rather than nix versions nix is doing io-safety which is an incompatible change. It's hard to write code which works with both versions of nix because BorrowedFd is in Rust 1.66 which is higher than our MSRV. Partially based on code from Peter Green. Signed-off-by: Ian Jackson --- server/daemon.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/daemon.rs b/server/daemon.rs index e3018fa..9b86bbe 100644 --- a/server/daemon.rs +++ b/server/daemon.rs @@ -88,7 +88,7 @@ fn c_itoa(value: c_int, buf: &mut [u8; ITOA_BUFL]) -> &str { } unsafe fn mdup2(oldfd: RawFd, newfd: RawFd, what: &str) { - match dup2(oldfd, newfd) { + match Errno::result(libc::dup2(oldfd, newfd)) { Ok(got) if got == newfd => { }, Ok(_) => crashm("dup2 gave wrong return value"), Err(e) => crashv!("dup2 ", what, ": ", e.desc()), @@ -106,7 +106,11 @@ unsafe fn write_status(st_wfd: RawFd, estatus: u8) { unsafe fn parent(st_rfd: RawFd) -> ! { let mut exitstatus = 0u8; loop { - match read(st_rfd, slice::from_mut(&mut exitstatus)) { + // TODO rationalise/revert this when MSRV >= 1.66 and/or nix >= 30 + let es_sl = slice::from_mut(&mut exitstatus); + let es_sl_l = es_sl.len(); + let es_sl_p = es_sl.as_mut_ptr() as _; + match Errno::result(libc::read(st_rfd, es_sl_p, es_sl_l)) { Ok(0) => crashm("startup/daemonisation failed"), Ok(1) => libc::_exit(exitstatus.into()), Ok(_) => crashm("read startup: excess read!"), -- 2.30.2