From 71be76265fb85d14092576f7511865865369c8cd Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Fri, 10 Jul 2026 17:31:14 -0700 Subject: [PATCH] Proposal typo fixes --- Proposals/0007-FileDescriptor-dup3-pipe2.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Proposals/0007-FileDescriptor-dup3-pipe2.md b/Proposals/0007-FileDescriptor-dup3-pipe2.md index 85b1ed5..f769f61 100644 --- a/Proposals/0007-FileDescriptor-dup3-pipe2.md +++ b/Proposals/0007-FileDescriptor-dup3-pipe2.md @@ -1,7 +1,7 @@ # Add support for `dup3` and `pipe2` POSIX API to `FileDescriptor` * Proposal: SYS-0007 -- Author(s): Jake Petroules , Guillaume Lessard +* Authors: Jake Petroules , Guillaume Lessard * Other Reviews: [Swift Forums Pitch](https://forums.swift.org/t/82486) @@ -21,11 +21,11 @@ This proposal adds additional `FileDescriptor` overloads to cover new POSIX 2024 It is considered best practice to set the `O_CLOEXEC` (close-on-exec) bit on newly created file descriptors to prevent them from being inherited by subprocesses. -Some POSIX functions such as `open` provide a "flags" parameter allowing this the close-on-exec bit to be set atomically on the newly created file descriptor. However, others provide no such flags parameter, and require the caller to use `fcntl` to set the close-on-exec bit after the fact. This can lead to race conditions and security bugs where file descriptors can be inherited between calling the function creating the file descriptor, and calling `fcntl`. +Some POSIX functions such as `open` provide a "flags" parameter allowing the close-on-exec bit to be set atomically on the newly created file descriptor. However, others provide no such flags parameter, and require the caller to use `fcntl` to set the close-on-exec bit after the fact. This can lead to race conditions and security bugs where file descriptors can be inherited between calling the function creating the file descriptor, and calling `fcntl`. POSIX 2024 corrects this deficiency for `dup2` and `pipe` by introducing `dup3` and `pipe2` variants that allow the close-on-exec bit to be set atomically. -While it's *also* considered best practice for subprocess spawning code to close all open file descriptors in the newly created subprocess (swiftlang/swift-subprocess does this for example), there is no guarantee that a user of Swift System is using a mechanism which does so throughout their entire process, and might be using process spawning code they don't control. Adding the proposed overloads will allow developers to write code which adopts a posture of defence in depth with respect to opened file descriptors. +While it's *also* considered best practice for subprocess spawning code to close all open file descriptors in the newly created subprocess (swiftlang/swift-subprocess does this for example), there is no guarantee that a user of Swift System is using a mechanism which does so throughout their entire process, and might be using process spawning code they don't control. Adding the proposed overloads will allow developers to write code which adopts a posture of defense in depth with respect to opened file descriptors. ## Proposed solution @@ -38,7 +38,7 @@ import System let fd0 = try FileDescriptor.open("/tmp/test.txt", .readOnly) let fd1 = FileDescriptor(rawValue: 731) -let fd2 = fd0.duplicate(as: fd1, options: [.closeOnFork, .closeOnExec]) +let fd2 = try fd0.duplicate(as: fd1, options: [.closeOnFork, .closeOnExec]) ``` ## Detailed design