-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds signal termination handling when using control C, ensuring proce…
…sses are also terminated
- Loading branch information
Showing
5 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// signals.swift | ||
// overlook | ||
// | ||
// Created by Wesley Cope on 11/29/16. | ||
// | ||
// | ||
|
||
import Foundation | ||
import Darwin | ||
|
||
public enum Signal { | ||
case hup | ||
case int | ||
case quit | ||
case abrt | ||
case kill | ||
case alrm | ||
case term | ||
case user(Int) | ||
|
||
public static var all:[Signal] = [.hup, .int, .quit, .abrt, .kill, .alrm, .term,] | ||
|
||
public var rawValue:Int32 { | ||
switch self { | ||
case .hup: return Int32(SIGHUP) | ||
case .int: return Int32(SIGINT) | ||
case .quit: return Int32(SIGQUIT) | ||
case .abrt: return Int32(SIGABRT) | ||
case .kill: return Int32(SIGKILL) | ||
case .alrm: return Int32(SIGALRM) | ||
case .term: return Int32(SIGTERM) | ||
case .user(let sig): return Int32(sig) | ||
} | ||
} | ||
} | ||
|
||
public typealias SignalHandler = @convention(c)(Int32) -> Void | ||
|
||
public func signalTrap(_ signal:Signal, handler:SignalHandler) { | ||
var signalAction = sigaction(__sigaction_u: unsafeBitCast(handler, to: __sigaction_u.self), sa_mask: 0, sa_flags: 0) | ||
_ = withUnsafePointer(to: &signalAction) { actionPointer in | ||
|
||
Darwin.sigaction(signal.rawValue, actionPointer, nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters