Skip to content

Commit 2bda2da

Browse files
committed
Revert "Close lower file descriptors on spawn"
This reverts commit 6efb1f7.
1 parent 6efb1f7 commit 2bda2da

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

Diff for: Sources/Testing/ExitTests/SpawnProcess.swift

+3-12
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func spawnExecutable(
117117
}
118118

119119
// Forward standard I/O streams and any explicitly added file handles.
120-
var inheritedFDs: Set = [STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO]
120+
var highestFD = max(STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)
121121
func inherit(_ fileHandle: borrowing FileHandle, as standardFD: CInt? = nil) throws {
122122
try fileHandle.withUnsafePOSIXFileDescriptor { fd in
123123
guard let fd else {
@@ -129,7 +129,7 @@ func spawnExecutable(
129129
#if SWT_TARGET_OS_APPLE
130130
_ = posix_spawn_file_actions_addinherit_np(fileActions, fd)
131131
#endif
132-
inheritedFDs.insert(fd)
132+
highestFD = max(highestFD, fd)
133133
}
134134
}
135135
}
@@ -152,15 +152,7 @@ func spawnExecutable(
152152
#if SWT_TARGET_OS_APPLE
153153
// Close all other file descriptors open in the parent.
154154
flags |= CShort(POSIX_SPAWN_CLOEXEC_DEFAULT)
155-
#else
156-
// Close all file descriptors up to the highest inherited one (except, of
157-
// course, the ones we want to keep open!)
158-
let highestFD = inheritedFDs.max()!
159-
for fd in 0 ..< highestFD where !inheritedFDs.contains(fd) {
160-
_ = posix_spawn_file_actions_addclose(fileActions, fd)
161-
}
162-
163-
#if os(Linux)
155+
#elseif os(Linux)
164156
#if !SWT_NO_DYNAMIC_LINKING
165157
// This platform doesn't have POSIX_SPAWN_CLOEXEC_DEFAULT, but we can at
166158
// least close all file descriptors higher than the highest inherited one.
@@ -183,7 +175,6 @@ func spawnExecutable(
183175
#else
184176
#warning("Platform-specific implementation missing: cannot close unused file descriptors")
185177
#endif
186-
#endif
187178

188179
#if SWT_TARGET_OS_APPLE && DEBUG
189180
// Start the process suspended so we can attach a debugger if needed.

0 commit comments

Comments
 (0)