From 5655d20a64bc9aa1ff18b440e30dc3f3bac72000 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 3 Dec 2025 21:34:40 +0100 Subject: [PATCH] daemon: Remove libredox dependency --- Cargo.lock | 1 - daemon/Cargo.toml | 1 - daemon/src/lib.rs | 26 +++++++++++++------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb8a818c24..427785218d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -506,7 +506,6 @@ name = "daemon" version = "0.0.0" dependencies = [ "libc", - "libredox", ] [[package]] diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index 34440ade85..b15ee92f7e 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -5,4 +5,3 @@ edition = "2024" [dependencies] libc = "0.2.177" -libredox = "0.1.10" diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 0f2ec015fc..d347e7c838 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -1,23 +1,23 @@ #![feature(never_type)] -use libredox::{error::{Error, Result}, errno::{EINTR, EIO}}; +use std::io; #[must_use = "Daemon::ready must be called"] pub struct Daemon { write_pipe: libc::c_int, } -fn errno() -> libc::c_int { - unsafe { libc::__errno_location().read() } +fn errno() -> io::Error { + io::Error::last_os_error() } impl Daemon { - pub fn new !>(f: F) -> Result { + pub fn new !>(f: F) -> io::Result { let mut pipes = [0; 2]; match unsafe { libc::pipe(pipes.as_mut_ptr()) } { 0 => (), - -1 => return Err(Error::new(errno())), + -1 => return Err(errno()), _ => unreachable!(), } @@ -29,7 +29,7 @@ impl Daemon { f(Daemon { write_pipe }) } - -1 => return Err(Error::new(errno())), + -1 => return Err(errno()), _pid => { let _ = unsafe { libc::close(write_pipe) }; @@ -37,8 +37,8 @@ impl Daemon { let res = loop { match unsafe { libc::read(read_pipe, data.as_mut_ptr().cast(), data.len()) } { - -1 if errno() == EINTR => continue, - -1 => break Err(Error::new(errno())), + -1 if errno().kind() == io::ErrorKind::Interrupted => continue, + -1 => break Err(errno()), count => break Ok(count as usize), } @@ -49,21 +49,21 @@ impl Daemon { if res? == 1 { unsafe { libc::_exit(data[0].into()) }; } else { - Err(Error::new(EIO)) + Err(io::Error::from_raw_os_error(libc::EIO)) } } } } - pub fn ready(self) -> Result<()> { + pub fn ready(self) -> io::Result<()> { let res; unsafe { let src = [0_u8]; res = loop { match libc::write(self.write_pipe, src.as_ptr().cast(), src.len()) { - -1 if errno() == EINTR => continue, - -1 => break Err(Error::new(errno())), + -1 if errno().kind() == io::ErrorKind::Interrupted => continue, + -1 => break Err(errno()), count => break Ok(count), } }; @@ -73,7 +73,7 @@ impl Daemon { if res? == 1 { Ok(()) } else { - Err(Error::new(EIO)) + Err(io::Error::from_raw_os_error(libc::EIO)) } } }