@@ -48,6 +48,12 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
4848 /* https://www.gnu.org/software/libc/manual/html_node/Program-Error-Signals.html */
4949
5050 public static var programErrorSignals : Set < Signal > {
51+ let platformDependant : Set < Signal >
52+ #if !os(Linux)
53+ platformDependant = Set ( arrayLiteral: . emulatorTrap)
54+ #else
55+ platformDependant = Set ( )
56+ #endif
5157 return Set ( arrayLiteral:
5258 . arithmeticError,
5359 . illegalInstruction,
@@ -56,9 +62,8 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
5662 . abortTrap,
5763 . iot,
5864 . traceBreakpointTrap,
59- . emulatorTrap,
6065 . badSystemCall
61- )
66+ ) . union ( platformDependant )
6267 }
6368
6469 /**
@@ -74,7 +79,9 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
7479 /** Usually the same as `abortTrap`. */
7580 public static let iot = Signal ( rawValue: SIGIOT)
7681 public static let traceBreakpointTrap = Signal ( rawValue: SIGTRAP)
82+ #if !os(Linux)
7783 public static let emulatorTrap = Signal ( rawValue: SIGEMT)
84+ #endif
7885 public static let badSystemCall = Signal ( rawValue: SIGSYS)
7986
8087 /* *** Termination Signals *** */
@@ -128,8 +135,10 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
128135
129136 public static let ioPossible = Signal ( rawValue: SIGIO)
130137 public static let urgentIOCondition = Signal ( rawValue: SIGURG)
138+ #if os(Linux)
131139 /* System V signal name similar to SIGIO */
132- // public static let poll = Signal(rawValue: SIGPOLL)
140+ public static let poll = Signal ( rawValue: SIGPOLL)
141+ #endif
133142
134143 /* *** Job Control Signals *** */
135144 /* https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html */
@@ -147,7 +156,7 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
147156
148157 public static let childExited = Signal ( rawValue: SIGCHLD)
149158 /* Obsolete name for SIGCHLD */
150- // public static let cildExited = Signal(rawValue: SIGCLD)
159+ // public static let cildExited = Signal(rawValue: SIGCLD)
151160 public static let continued = Signal ( rawValue: SIGCONT)
152161 /** Suspends the program. Cannot be handled, ignored or blocked. */
153162 public static let suspendedBySignal = Signal ( rawValue: SIGSTOP)
@@ -168,26 +177,48 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
168177 }
169178
170179 public static let brokenPipe = Signal ( rawValue: SIGPIPE)
171- // public static let resourceLost = Signal(rawValue: SIGLOST)
180+ // public static let resourceLost = Signal(rawValue: SIGLOST)
172181 public static let cputimeLimitExceeded = Signal ( rawValue: SIGXCPU)
173182 public static let filesizeLimitExceeded = Signal ( rawValue: SIGXFSZ)
174183
175184 /* *** Miscellaneous Signals *** */
176185 /* https://www.gnu.org/software/libc/manual/html_node/Miscellaneous-Signals.html */
177186
178187 public static var miscellaneousSignals : Set < Signal > {
188+ let platformDependant : Set < Signal >
189+ #if !os(Linux)
190+ platformDependant = Set ( arrayLiteral: . informationRequest)
191+ #else
192+ platformDependant = Set ( )
193+ #endif
179194 return Set ( arrayLiteral:
180195 . userDefinedSignal1,
181196 . userDefinedSignal2,
182- . windowSizeChanges,
183- . informationRequest
184- )
197+ . windowSizeChanges
198+ ) . union ( platformDependant)
185199 }
186200
187201 public static let userDefinedSignal1 = Signal ( rawValue: SIGUSR1)
188202 public static let userDefinedSignal2 = Signal ( rawValue: SIGUSR2)
189203 public static let windowSizeChanges = Signal ( rawValue: SIGWINCH)
204+ #if !os(Linux)
190205 public static let informationRequest = Signal ( rawValue: SIGINFO)
206+ #endif
207+
208+ #if os(Linux)
209+ /* *** Other Signals *** */
210+ /* Not in GNU doc */
211+
212+ public static var otherSignals : Set < Signal > {
213+ return Set ( arrayLiteral:
214+ . stackFault,
215+ . powerFailure
216+ )
217+ }
218+
219+ public static let stackFault = Signal ( rawValue: SIGSTKFLT)
220+ public static let powerFailure = Signal ( rawValue: SIGPWR)
221+ #endif
191222
192223 public static func set( from sigset: sigset_t ) -> Set < Signal > {
193224 var sigset = sigset
@@ -231,6 +262,7 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
231262 }
232263
233264 /** Will return `usr1` or similar for `.userDefinedSignal1` for instance. */
265+ #if !os(Linux)
234266 public var signalName : String ? {
235267 guard rawValue >= 0 && rawValue < NSIG else {
236268 return nil
@@ -242,6 +274,7 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
242274 } )
243275 } )
244276 }
277+ #endif
245278
246279 /**
247280 Return a user readable description of the signal (always in English I think). */
@@ -258,7 +291,11 @@ public struct Signal : RawRepresentable, Hashable, Codable, CaseIterable, Custom
258291 }
259292
260293 public var description : String {
294+ #if !os(Linux)
261295 return " SIG \( ( signalName ?? " \( rawValue) " ) . uppercased ( ) ) "
296+ #else
297+ return " \( signalDescription ?? " \( rawValue) " ) "
298+ #endif
262299 }
263300
264301}
0 commit comments