@@ -117,7 +117,7 @@ func spawnExecutable(
117
117
}
118
118
119
119
// 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)
121
121
func inherit( _ fileHandle: borrowing FileHandle , as standardFD: CInt ? = nil ) throws {
122
122
try fileHandle. withUnsafePOSIXFileDescriptor { fd in
123
123
guard let fd else {
@@ -129,7 +129,7 @@ func spawnExecutable(
129
129
#if SWT_TARGET_OS_APPLE
130
130
_ = posix_spawn_file_actions_addinherit_np ( fileActions, fd)
131
131
#endif
132
- inheritedFDs . insert ( fd)
132
+ highestFD = max ( highestFD , fd)
133
133
}
134
134
}
135
135
}
@@ -152,15 +152,7 @@ func spawnExecutable(
152
152
#if SWT_TARGET_OS_APPLE
153
153
// Close all other file descriptors open in the parent.
154
154
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)
164
156
#if !SWT_NO_DYNAMIC_LINKING
165
157
// This platform doesn't have POSIX_SPAWN_CLOEXEC_DEFAULT, but we can at
166
158
// least close all file descriptors higher than the highest inherited one.
@@ -183,7 +175,6 @@ func spawnExecutable(
183
175
#else
184
176
#warning("Platform-specific implementation missing: cannot close unused file descriptors")
185
177
#endif
186
- #endif
187
178
188
179
#if SWT_TARGET_OS_APPLE && DEBUG
189
180
// Start the process suspended so we can attach a debugger if needed.
0 commit comments