From 1e341ff782aa8e07e632c7f29c5d90ceaadd2bec Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Mon, 13 Jul 2026 20:22:31 +0300 Subject: [PATCH] =?UTF-8?q?init:=20fix=20pipe=20FILETABLE=20desync=20?= =?UTF-8?q?=E2=80=94=20use=20libc::pipe2=20instead=20of=20raw=20syscall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- init/src/service.rs | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/init/src/service.rs b/init/src/service.rs index d4f15baeda..d34c736bac 100644 --- a/init/src/service.rs +++ b/init/src/service.rs @@ -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)) }