Skip to content

Commit 541096a

Browse files
make posix spawn file actions in linux and macos
1 parent 73ac7c2 commit 541096a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Sources/CommandExecutor.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ import Foundation
22

33
typealias ExecutorReturnValue = (status: Int, standardOutput: String, standardError: String)
44

5+
enum STDLIB {
6+
#if os(Linux)
7+
typealias _posix_spawn_file_actions_t = posix_spawn_file_actions_t
8+
#else
9+
typealias _posix_spawn_file_actions_t = posix_spawn_file_actions_t?
10+
#endif
11+
12+
#if os(Linux)
13+
static func _make_posix_spawn_file_actions_t() -> _posix_spawn_file_actions_t {
14+
posix_spawn_file_actions_t()
15+
}
16+
#else
17+
static func _make_posix_spawn_file_actions_t() -> _posix_spawn_file_actions_t {
18+
nil
19+
}
20+
#endif
21+
}
22+
23+
524
class CommandExecutor {
625
static var currentTaskExecutor: TaskExecutor = ActualTaskExecutor()
726

@@ -83,7 +102,7 @@ class InteractiveTaskExecutor: TaskExecutor {
83102

84103
let outputPipe: [Int32] = [-1, -1]
85104

86-
var childFDActions: posix_spawn_file_actions_t!
105+
var childFDActions = STDLIB._make_posix_spawn_file_actions_t()
87106
posix_spawn_file_actions_init(&childFDActions)
88107
posix_spawn_file_actions_adddup2(&childFDActions, outputPipe[1], 1)
89108
posix_spawn_file_actions_adddup2(&childFDActions, outputPipe[1], 2)
@@ -108,7 +127,7 @@ class LogTaskExecutor: TaskExecutor {
108127
func execute(_ commandParts: [String]) -> ExecutorReturnValue {
109128
let argv: [UnsafeMutablePointer<CChar>?] = commandParts.map { $0.withCString(strdup) }
110129
var pid: pid_t = 0
111-
var childFDActions: posix_spawn_file_actions_t!
130+
var childFDActions = STDLIB._make_posix_spawn_file_actions_t()
112131
let outputPipe: Int32 = 69
113132
let outerrPipe: Int32 = 70
114133

0 commit comments

Comments
 (0)