1use bitflags::*;
2
3pub const MAX_SIG: usize = 31;
4
5bitflags! {
6 pub struct SignalFlags: u32 {
7 const SIGDEF = 1; const SIGHUP = 1 << 1;
9 const SIGINT = 1 << 2;
10 const SIGQUIT = 1 << 3;
11 const SIGILL = 1 << 4;
12 const SIGTRAP = 1 << 5;
13 const SIGABRT = 1 << 6;
14 const SIGBUS = 1 << 7;
15 const SIGFPE = 1 << 8;
16 const SIGKILL = 1 << 9;
17 const SIGUSR1 = 1 << 10;
18 const SIGSEGV = 1 << 11;
19 const SIGUSR2 = 1 << 12;
20 const SIGPIPE = 1 << 13;
21 const SIGALRM = 1 << 14;
22 const SIGTERM = 1 << 15;
23 const SIGSTKFLT = 1 << 16;
24 const SIGCHLD = 1 << 17;
25 const SIGCONT = 1 << 18;
26 const SIGSTOP = 1 << 19;
27 const SIGTSTP = 1 << 20;
28 const SIGTTIN = 1 << 21;
29 const SIGTTOU = 1 << 22;
30 const SIGURG = 1 << 23;
31 const SIGXCPU = 1 << 24;
32 const SIGXFSZ = 1 << 25;
33 const SIGVTALRM = 1 << 26;
34 const SIGPROF = 1 << 27;
35 const SIGWINCH = 1 << 28;
36 const SIGIO = 1 << 29;
37 const SIGPWR = 1 << 30;
38 const SIGSYS = 1 << 31;
39 }
40}
41
42impl SignalFlags {
43 pub fn check_error(&self) -> Option<(i32, &'static str)> {
44 if self.contains(Self::SIGINT) {
45 Some((-2, "Killed, SIGINT=2"))
46 } else if self.contains(Self::SIGILL) {
47 Some((-4, "Illegal Instruction, SIGILL=4"))
48 } else if self.contains(Self::SIGABRT) {
49 Some((-6, "Aborted, SIGABRT=6"))
50 } else if self.contains(Self::SIGFPE) {
51 Some((-8, "Erroneous Arithmetic Operation, SIGFPE=8"))
52 } else if self.contains(Self::SIGKILL) {
53 Some((-9, "Killed, SIGKILL=9"))
54 } else if self.contains(Self::SIGSEGV) {
55 Some((-11, "Segmentation Fault, SIGSEGV=11"))
56 } else {
57 None
59 }
60 }
61}