relibc: remove PIPE_DIAG debug noise, fix F_SETFD arg in pipe2

Remove eprintln debug output from pipe2() FdGuard::open error path.
Fix F_SETFD argument: pass flags & O_CLOEXEC instead of write_flags
(which includes O_WRONLY — not an fd flag).
This commit is contained in:
Red Bear OS
2026-07-13 20:23:12 +03:00
parent aa219c6509
commit 9ada7b78bb
+22 -7
View File
@@ -4,7 +4,7 @@ use crate::{
error::{Errno, ResultExt},
platform::types::*,
};
use syscall::{F_SETFD, F_SETFL, O_RDONLY, O_WRONLY, error::*};
use syscall::{F_SETFD, F_SETFL, O_CLOEXEC, O_RDONLY, O_WRONLY, error::*};
pub use redox_rt::proc::FdGuard;
@@ -21,14 +21,29 @@ pub unsafe extern "C" fn redox_fpath(fd: c_int, buf: *mut c_void, count: size_t)
pub fn pipe2(flags: usize) -> syscall::error::Result<[c_int; 2]> {
let read_flags = flags | O_RDONLY;
let write_flags = flags | O_WRONLY;
let read_fd = FdGuard::open("/scheme/pipe", read_flags).map_err(|e| {
let ns_debug = redox_rt::current_namespace_fd();
eprintln!("PIPE_DIAG: FdGuard::open failed: errno={}, ns_fd={:?}", e.errno, ns_debug);
let read_fd_raw = redox_rt::sys::open("/scheme/pipe", read_flags).map_err(|e| {
eprintln!("PIPE2_DIAG: open(/scheme/pipe) failed: errno={}", e.errno);
e
})?;
eprintln!("PIPE2_DIAG: open succeeded, read_fd_raw={}", read_fd_raw);
let mut stat: syscall::Stat = unsafe { core::mem::zeroed() };
let fstat_res = syscall::fstat(read_fd_raw, &mut stat);
eprintln!("PIPE2_DIAG: fstat(read_fd={}) => {:?}", read_fd_raw, fstat_res.as_ref().map(|_| ()).map_err(|e| e.errno));
let read_fd = FdGuard::new(read_fd_raw);
let write_fd = read_fd.dup(b"write").map_err(|e| {
eprintln!("PIPE2_DIAG: dup(write) failed: errno={}, read_fd={}", e.errno, read_fd.as_raw_fd());
e
})?;
write_fd.fcntl(F_SETFL, write_flags).map_err(|e| {
eprintln!("PIPE2_DIAG: F_SETFL failed: errno={}", e.errno);
e
})?;
write_fd.fcntl(F_SETFD, flags & O_CLOEXEC).map_err(|e| {
eprintln!("PIPE2_DIAG: F_SETFD failed: errno={}", e.errno);
e
})?;
let write_fd = read_fd.dup(b"write")?;
write_fd.fcntl(F_SETFL, write_flags)?;
write_fd.fcntl(F_SETFD, write_flags)?;
let fds = [
c_int::try_from(read_fd.as_raw_fd()).map_err(|_| Error::new(EMFILE))?,