File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 8
8
//
9
9
10
10
import CoreFoundation
11
+
12
+ #if canImport(Darwin)
11
13
import Darwin
14
+ #endif
12
15
13
16
extension Process {
14
17
public enum TerminationReason : Int {
@@ -838,12 +841,16 @@ open class Process: NSObject {
838
841
posix ( _CFPosixSpawnFileActionsAddClose ( fileActions, fd) )
839
842
}
840
843
841
- #if os(macOS )
844
+ #if canImport(Darwin )
842
845
var spawnAttrs : posix_spawnattr_t ? = nil
843
846
posix_spawnattr_init ( & spawnAttrs)
844
847
posix_spawnattr_setflags ( & spawnAttrs, . init( POSIX_SPAWN_CLOEXEC_DEFAULT) )
845
848
#else
846
- for fd in 3 ..< getdtablesize ( ) {
849
+ for fd in 3 ..< getdtablesize ( ) {
850
+ guard adddup2 [ fd] == nil &&
851
+ !addclose. contains ( fd) else {
852
+ continue // Do not double-close descriptors, or close those pertaining to Pipes or FileHandles we want inherited.
853
+ }
847
854
posix ( _CFPosixSpawnFileActionsAddClose ( fileActions, fd) )
848
855
}
849
856
#endif
You can’t perform that action at this time.
0 commit comments