chiark / gitweb /
Use libc::dup2 and libc::read rather than nix versions
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Sep 2025 09:56:13 +0000 (10:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Sep 2025 10:06:48 +0000 (11:06 +0100)
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 <ijackson@chiark.greenend.org.uk>
server/daemon.rs

index e3018fa848e10b491524887ea2741eb5d2567650..9b86bbe7d9ba7aaa3d5507a97a37267c4781afbf 100644 (file)
@@ -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!"),