Skip to content

Commit

Permalink
make posix spawn file actions in linux and macos
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangel-dev committed May 4, 2020
1 parent 73ac7c2 commit 541096a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Sources/CommandExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ import Foundation

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

enum STDLIB {
#if os(Linux)
typealias _posix_spawn_file_actions_t = posix_spawn_file_actions_t
#else
typealias _posix_spawn_file_actions_t = posix_spawn_file_actions_t?
#endif

#if os(Linux)
static func _make_posix_spawn_file_actions_t() -> _posix_spawn_file_actions_t {
posix_spawn_file_actions_t()
}
#else
static func _make_posix_spawn_file_actions_t() -> _posix_spawn_file_actions_t {
nil
}
#endif
}


class CommandExecutor {
static var currentTaskExecutor: TaskExecutor = ActualTaskExecutor()

Expand Down Expand Up @@ -83,7 +102,7 @@ class InteractiveTaskExecutor: TaskExecutor {

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

var childFDActions: posix_spawn_file_actions_t!
var childFDActions = STDLIB._make_posix_spawn_file_actions_t()
posix_spawn_file_actions_init(&childFDActions)
posix_spawn_file_actions_adddup2(&childFDActions, outputPipe[1], 1)
posix_spawn_file_actions_adddup2(&childFDActions, outputPipe[1], 2)
Expand All @@ -108,7 +127,7 @@ class LogTaskExecutor: TaskExecutor {
func execute(_ commandParts: [String]) -> ExecutorReturnValue {
let argv: [UnsafeMutablePointer<CChar>?] = commandParts.map { $0.withCString(strdup) }
var pid: pid_t = 0
var childFDActions: posix_spawn_file_actions_t!
var childFDActions = STDLIB._make_posix_spawn_file_actions_t()
let outputPipe: Int32 = 69
let outerrPipe: Int32 = 70

Expand Down

0 comments on commit 541096a

Please sign in to comment.