Skip to content

Commit

Permalink
Use the NSConcreteTask.setStartsNewProcessGroup private API to term…
Browse files Browse the repository at this point in the history
…inate subprocesses when the parent process exits
  • Loading branch information
ikesyo committed Sep 10, 2018
1 parent 8420220 commit 05672c3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ extension Task {
process.launchPath = self.launchPath
process.arguments = self.arguments

// This is for terminating subprocesses when the parent process exits.
// See https://github.com/Carthage/ReactiveTask/issues/3 for the details.
let selector = Selector(("setStartsNewProcessGroup:"))
if process.responds(to: selector) {
process.perform(selector, with: false as NSNumber)
}

if let cwd = self.workingDirectoryPath {
process.currentDirectoryPath = cwd
}
Expand Down Expand Up @@ -484,8 +491,8 @@ extension Task {
process.standardError = stderrPipe.writeHandle

group.enter()
process.terminationHandler = { nstask in
let terminationStatus = nstask.terminationStatus
process.terminationHandler = { process in
let terminationStatus = process.terminationStatus
if terminationStatus == EXIT_SUCCESS {
// Wait for stderr to finish, then pass
// through stdout.
Expand Down

0 comments on commit 05672c3

Please sign in to comment.