mirror of
https://github.com/apple/container.git
synced 2026-10-16 19:19:15 +00:00
Signal: Expose helpful helper methods (#721)
- Method to grab the signal name - Convert macOS signal to linux equivalent
This commit is contained in:
1 parent
f2c42402e7
commit
57d157c82a
1 file changed
+29
@@ -254,6 +254,35 @@ extension Signal {
|
||||
|
||||
#endif
|
||||
|
||||
extension Signal {
|
||||
private static let platformToName: [Int32: String] =
|
||||
Dictionary(Signal.platform.map { ($0.value, $0.key) }, uniquingKeysWith: { first, _ in first })
|
||||
|
||||
/// Returns the canonical name for this signal on the current platform.
|
||||
public func platformName() -> String? {
|
||||
Self.platformName(self.rawValue)
|
||||
}
|
||||
|
||||
/// Returns the canonical name for a signal number on the current platform.
|
||||
public static func platformName(_ signal: Int32) -> String? {
|
||||
platformToName[signal]
|
||||
}
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
extension Signal {
|
||||
/// Converts a macOS signal to the equivalent Linux signal.
|
||||
public func linuxSignal() -> Signal? {
|
||||
guard let name = Self.platformToName[self.rawValue],
|
||||
let linuxNumber = Signal.linux[name]
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
return Signal(rawValue: linuxNumber)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extension Signal: ExpressibleByIntegerLiteral {
|
||||
public init(integerLiteral value: Int32) {
|
||||
self.rawValue = value
|
||||
|
||||
Reference in new issue
Block a user