pipe2/dup3 O_CLOEXEC - #1520
Open
jakepetroules wants to merge 1 commit into
Open
Conversation
jakepetroules
requested review from
cmcgee1024,
daveinglis,
mhrawdon,
owenv,
rconnell9 and
rjmansfield
as code owners
July 8, 2026 00:11
Add safeOpen / safePipe / safeDuplicate helpers on FileDescriptor that always request close-on-exec, so descriptors created by the build system are not leaked into the child processes it spawns. They route through the swift-system pipe2/dup3 wrappers where those are available: - safePipe uses FileDescriptor.pipe(options: .closeOnExec) on non-Apple platforms (including Windows), and on Apple platforms running OS 27 or later via the SDK's System framework; older Apple OSes fall back to a plain pipe(). - safeDuplicate(as:) uses FileDescriptor.duplicate(as:options:) on non-Apple platforms (dup3 is unavailable on Windows) and on Apple OS 27 or later; elsewhere it falls back to a plain dup2(). - safeDuplicate() (no target) uses fcntl(F_DUPFD_CLOEXEC) to atomically obtain the lowest-numbered unused descriptor with close-on-exec set; on Windows, which has no F_DUPFD_CLOEXEC, it falls back to a plain dup(). - safeOpen forces OpenOptions.closeOnExec. Adopt these wrappers in FSProxy, PbxCp, XCBuildDataArchive, LineReader, and the build service entry point, and require swift-system 1.7.3.
jakepetroules
force-pushed
the
worktree-cloexec-swift-system-1.7
branch
from
July 8, 2026 01:38
b85bab9 to
12e2137
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
safeOpen/safePipe/safeDuplicatehelpers onFileDescriptorthat always request close-on-exec, so descriptors created by the build system are not leaked into the child processes it spawns. They route through the swift-system pipe2/dup3 wrappers where those are available:safePipeusesFileDescriptor.pipe(options: .closeOnExec)on non-Apple platforms (including Windows), and on Apple platforms running OS 27 or later via the SDK'sSystemframework; older Apple OSes fall back to a plainpipe().safeDuplicate(as:)usesFileDescriptor.duplicate(as:options:)on non-Apple platforms (dup3 is unavailable on Windows) and on Apple OS 27 or later; elsewhere it falls back to a plaindup2().safeDuplicate()(no target) usesfcntl(F_DUPFD_CLOEXEC)to atomically obtain the lowest-numbered unused descriptor with close-on-exec set; on Windows, which has noF_DUPFD_CLOEXEC, it falls back to a plaindup().safeOpenforcesOpenOptions.closeOnExec.Adopt these wrappers in
FSProxy,PbxCp,XCBuildDataArchive,LineReader, and the build service entry point, and require swift-system 1.7.3 (which exposesOpenOptions.closeOnExecon Windows).