Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly kill processes spawned by mac-crafter if mac-crafter quits/is killed/etc #7164

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions admin/osx/mac-crafter/Sources/Utils/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,40 @@

import Foundation

var task: Process?

@discardableResult
func run(
_ launchPath: String,
_ args: [String],
env: [String: String]? = nil,
quiet: Bool = false
) -> Int32 {
let task = Process()
task.launchPath = launchPath
task.arguments = args
defer { task = nil }
task = Process()

signal(SIGINT) { _ in
task?.terminate() // Send terminate signal to the task
exit(0) // Exit the script after cleanup
}

task?.launchPath = launchPath
task?.arguments = args

if let env,
let combinedEnv = task.environment?.merging(env, uniquingKeysWith: { (_, new) in new })
let combinedEnv = task?.environment?.merging(env, uniquingKeysWith: { (_, new) in new })
{
task.environment = combinedEnv
task?.environment = combinedEnv
}

if quiet {
task.standardOutput = nil
task.standardError = nil
task?.standardOutput = nil
task?.standardError = nil
}

task.launch()
task.waitUntilExit()
return task.terminationStatus
task?.launch()
task?.waitUntilExit()
return task?.terminationStatus ?? 1
}

func run(
Expand Down
Loading