From 57d157c82aa73c2dfd63a56aee80f934ad453470 Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Fri, 1 May 2026 14:51:40 -0700 Subject: [PATCH] Signal: Expose helpful helper methods (#721) - Method to grab the signal name - Convert macOS signal to linux equivalent --- Sources/Containerization/Signal.swift | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sources/Containerization/Signal.swift b/Sources/Containerization/Signal.swift index 02bb9e9e..caef367c 100644 --- a/Sources/Containerization/Signal.swift +++ b/Sources/Containerization/Signal.swift @@ -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