From 91ba44e2fa2e315b102be5a56dc036007019d160 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 17 Nov 2025 17:39:44 -0700 Subject: [PATCH] Implement F_DUPFD_CLOEXEC --- Cargo.lock | 4 ++-- src/syscall/debug.rs | 1 + src/syscall/fs.rs | 13 +++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a1a41c231..9aa5bb9a57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,8 +208,8 @@ checksum = "64072665120942deff5fd5425d6c1811b854f4939e7f1c01ce755f64432bbea7" [[package]] name = "redox_syscall" -version = "0.5.17" -source = "git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=master#aedadf4d5cb915e0c6a22a5c7358fa853354e21d" +version = "0.5.18" +source = "git+https://gitlab.redox-os.org/redox-os/syscall.git?branch=master#2d346f1d610a358d74cd40360cf7e5dcfc2120d7" dependencies = [ "bitflags 2.9.4", ] diff --git a/src/syscall/debug.rs b/src/syscall/debug.rs index d3c81ae3fc..f65965b8d2 100644 --- a/src/syscall/debug.rs +++ b/src/syscall/debug.rs @@ -111,6 +111,7 @@ pub fn format_call(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) - F_SETFD => "F_SETFD", F_SETFL => "F_SETFL", F_GETFL => "F_GETFL", + F_DUPFD_CLOEXEC => "F_DUPFD_CLOEXEC", _ => "UNKNOWN", }, c, diff --git a/src/syscall/fs.rs b/src/syscall/fs.rs index 3fb1f309bd..5ce467b46f 100644 --- a/src/syscall/fs.rs +++ b/src/syscall/fs.rs @@ -265,6 +265,7 @@ pub fn close(fd: FileHandle, token: &mut CleanLockToken) -> Result<()> { fn duplicate_file( fd: FileHandle, user_buf: UserSliceRo, + cloexec: bool, token: &mut CleanLockToken, ) -> Result { let (caller_ctx, file) = { @@ -279,7 +280,7 @@ fn duplicate_file( if user_buf.is_empty() { Ok(FileDescriptor { description: Arc::clone(&file.description), - cloexec: false, + cloexec, }) } else { let description = { *file.description.read() }; @@ -306,14 +307,14 @@ fn duplicate_file( Ok(FileDescriptor { description: new_description, - cloexec: false, + cloexec, }) } } /// Duplicate file descriptor pub fn dup(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) -> Result { - let new_file = duplicate_file(fd, buf, token)?; + let new_file = duplicate_file(fd, buf, false, token)?; context::current() .read(token.token()) @@ -332,7 +333,7 @@ pub fn dup2( Ok(new_fd) } else { let _ = close(new_fd, token); - let new_file = duplicate_file(fd, buf, token)?; + let new_file = duplicate_file(fd, buf, false, token)?; let context_ref = context::current(); let context = context_ref.read(token.token()); @@ -526,9 +527,9 @@ pub fn fcntl(fd: FileHandle, cmd: usize, arg: usize, token: &mut CleanLockToken) let description = file.description.read(); - if cmd == F_DUPFD { + if cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC { // Not in match because 'files' cannot be locked - let new_file = duplicate_file(fd, UserSlice::empty(), token)?; + let new_file = duplicate_file(fd, UserSlice::empty(), cmd == F_DUPFD_CLOEXEC, token)?; let context_lock = context::current(); let context = context_lock.read(token.token());