Skip to content

Commit d58e6bf

Browse files
authored
add support for trapping sigabrt, sigill, sigsegv (#184)
- sigabrt: usually generated by the abort() function. Useful for cleanup prior to termination. - sigill: issued if the user attempts to execute an illegal, malformed, or privileged instruction. - sigsegv: issued if the user makes an invalid memory reference, such as dereferencing a null or invalid pointer.
1 parent 05d3852 commit d58e6bf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Sources/UnixSignals/UnixSignal.swift

+21
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ import Dispatch
2626
/// Signals are standardized messages sent to a running program to trigger specific behavior, such as quitting or error handling
2727
public struct UnixSignal: Hashable, Sendable, CustomStringConvertible {
2828
internal enum Wrapped {
29+
case sigabrt
2930
case sighup
31+
case sigill
3032
case sigint
33+
case sigsegv
3134
case sigterm
3235
case sigusr1
3336
case sigusr2
@@ -49,12 +52,18 @@ public struct UnixSignal: Hashable, Sendable, CustomStringConvertible {
4952
return String(describing: self.wrapped)
5053
}
5154

55+
/// Usually generated by the abort() function. Useful for cleanup prior to termination.
56+
public static let sigabrt = Self(.sigabrt)
5257
/// Hang up detected on controlling terminal or death of controlling process.
5358
public static let sighup = Self(.sighup)
59+
/// Issued if the user attempts to execute an illegal, malformed, or privileged instruction.
60+
public static let sigill = Self(.sigill)
5461
/// Issued if the user sends an interrupt signal.
5562
public static let sigint = Self(.sigint)
5663
/// Issued if the user sends a quit signal.
5764
public static let sigquit = Self(.sigquit)
65+
/// Issued if the user makes an invalid memory reference, such as dereferencing a null or invalid pointer.
66+
public static let sigsegv = Self(.sigsegv)
5867
/// Software termination signal.
5968
public static let sigterm = Self(.sigterm)
6069
public static let sigusr1 = Self(.sigusr1)
@@ -70,12 +79,18 @@ extension UnixSignal.Wrapped: Sendable {}
7079
extension UnixSignal.Wrapped: CustomStringConvertible {
7180
var description: String {
7281
switch self {
82+
case .sigabrt:
83+
return "SIGABRT"
7384
case .sighup:
7485
return "SIGHUP"
86+
case .sigill:
87+
return "SIGILL"
7588
case .sigint:
7689
return "SIGINT"
7790
case .sigquit:
7891
return "SIGQUIT"
92+
case .sigsegv:
93+
return "SIGSEGV"
7994
case .sigterm:
8095
return "SIGTERM"
8196
case .sigusr1:
@@ -93,12 +108,18 @@ extension UnixSignal.Wrapped: CustomStringConvertible {
93108
extension UnixSignal.Wrapped {
94109
var rawValue: Int32 {
95110
switch self {
111+
case .sigabrt:
112+
return SIGABRT
96113
case .sighup:
97114
return SIGHUP
115+
case .sigill:
116+
return SIGILL
98117
case .sigint:
99118
return SIGINT
100119
case .sigquit:
101120
return SIGQUIT
121+
case .sigsegv:
122+
return SIGSEGV
102123
case .sigterm:
103124
return SIGTERM
104125
case .sigusr1:

0 commit comments

Comments
 (0)