daemon: Remove libredox dependency
This commit is contained in:
Generated
-1
@@ -506,7 +506,6 @@ name = "daemon"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libredox",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -5,4 +5,3 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.177"
|
||||
libredox = "0.1.10"
|
||||
|
||||
+13
-13
@@ -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: FnOnce(Daemon) -> !>(f: F) -> Result<!> {
|
||||
pub fn new<F: FnOnce(Daemon) -> !>(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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user