init: fix pipe FILETABLE desync — use libc::pipe2 instead of raw syscall

create_pipe() used raw syscall::openat/syscall::dup which allocate kernel
fds WITHOUT registering in relibc FILETABLE. Later FILETABLE-managed
syscalls (Command::spawn -> relibc pipe2) reserve the same fd numbers,
causing EEXIST in kernel insert_file.

Replace with libc::pipe2 which goes through relibc FILETABLE-aware path.
This commit is contained in:
Red Bear OS
2026-07-13 20:22:31 +03:00
parent 6e5da7259a
commit 1e341ff782
+7 -19
View File
@@ -37,25 +37,13 @@ pub enum ServiceType {
}
fn create_pipe() -> io::Result<(File, OwnedFd)> {
let ns_fd = libredox::call::getns()
.map_err(|e| io::Error::from_raw_os_error(e.errno()))?;
let rd_fd = syscall::openat(
ns_fd,
"/scheme/pipe",
syscall::flag::O_RDONLY | syscall::flag::O_CLOEXEC,
0,
)
.map_err(|e| io::Error::from_raw_os_error(e.errno))?;
let wr_raw = syscall::dup(rd_fd, b"write")
.map_err(|e| {
let _ = syscall::close(rd_fd);
io::Error::from_raw_os_error(e.errno)
})?;
let wr = unsafe { OwnedFd::from_raw_fd(wr_raw as i32) };
let rd = unsafe { File::from_raw_fd(rd_fd as i32) };
let mut fds = [0i32; 2];
let res = unsafe { libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC) };
if res != 0 {
return Err(io::Error::last_os_error());
}
let rd = unsafe { File::from_raw_fd(fds[0]) };
let wr = unsafe { OwnedFd::from_raw_fd(fds[1]) };
Ok((rd, wr))
}