| 1 | use crate::backend::c; |
| 2 | |
| 3 | /// A signal number for use with [`kill_process`], [`kill_process_group`], and |
| 4 | /// [`kill_current_process_group`]. |
| 5 | /// |
| 6 | /// [`kill_process`]: crate::process::kill_process |
| 7 | /// [`kill_process_group`]: crate::process::kill_process_group |
| 8 | /// [`kill_current_process_group`]: crate::process::kill_current_process_group |
| 9 | #[derive (Copy, Clone, Debug, Eq, PartialEq)] |
| 10 | #[repr (i32)] |
| 11 | pub enum Signal { |
| 12 | /// `SIGHUP` |
| 13 | Hup = c::SIGHUP, |
| 14 | /// `SIGINT` |
| 15 | Int = c::SIGINT, |
| 16 | /// `SIGQUIT` |
| 17 | Quit = c::SIGQUIT, |
| 18 | /// `SIGILL` |
| 19 | Ill = c::SIGILL, |
| 20 | /// `SIGTRAP` |
| 21 | Trap = c::SIGTRAP, |
| 22 | /// `SIGABRT`, aka `SIGIOT` |
| 23 | #[doc (alias = "Iot" )] |
| 24 | #[doc (alias = "Abrt" )] |
| 25 | Abort = c::SIGABRT, |
| 26 | /// `SIGBUS` |
| 27 | Bus = c::SIGBUS, |
| 28 | /// `SIGFPE` |
| 29 | Fpe = c::SIGFPE, |
| 30 | /// `SIGKILL` |
| 31 | Kill = c::SIGKILL, |
| 32 | /// `SIGUSR1` |
| 33 | #[cfg (not(target_os = "vita" ))] |
| 34 | Usr1 = c::SIGUSR1, |
| 35 | /// `SIGSEGV` |
| 36 | Segv = c::SIGSEGV, |
| 37 | /// `SIGUSR2` |
| 38 | #[cfg (not(target_os = "vita" ))] |
| 39 | Usr2 = c::SIGUSR2, |
| 40 | /// `SIGPIPE` |
| 41 | Pipe = c::SIGPIPE, |
| 42 | /// `SIGALRM` |
| 43 | #[doc (alias = "Alrm" )] |
| 44 | Alarm = c::SIGALRM, |
| 45 | /// `SIGTERM` |
| 46 | Term = c::SIGTERM, |
| 47 | /// `SIGSTKFLT` |
| 48 | #[cfg (not(any( |
| 49 | bsd, |
| 50 | solarish, |
| 51 | target_os = "aix" , |
| 52 | target_os = "haiku" , |
| 53 | target_os = "hurd" , |
| 54 | target_os = "nto" , |
| 55 | target_os = "vita" , |
| 56 | all( |
| 57 | linux_kernel, |
| 58 | any( |
| 59 | target_arch = "mips" , |
| 60 | target_arch = "mips32r6" , |
| 61 | target_arch = "mips64" , |
| 62 | target_arch = "mips64r6" , |
| 63 | target_arch = "sparc" , |
| 64 | target_arch = "sparc64" |
| 65 | ), |
| 66 | ) |
| 67 | )))] |
| 68 | Stkflt = c::SIGSTKFLT, |
| 69 | /// `SIGCHLD` |
| 70 | #[cfg (not(target_os = "vita" ))] |
| 71 | #[doc (alias = "Chld" )] |
| 72 | Child = c::SIGCHLD, |
| 73 | /// `SIGCONT` |
| 74 | #[cfg (not(target_os = "vita" ))] |
| 75 | Cont = c::SIGCONT, |
| 76 | /// `SIGSTOP` |
| 77 | #[cfg (not(target_os = "vita" ))] |
| 78 | Stop = c::SIGSTOP, |
| 79 | /// `SIGTSTP` |
| 80 | #[cfg (not(target_os = "vita" ))] |
| 81 | Tstp = c::SIGTSTP, |
| 82 | /// `SIGTTIN` |
| 83 | #[cfg (not(target_os = "vita" ))] |
| 84 | Ttin = c::SIGTTIN, |
| 85 | /// `SIGTTOU` |
| 86 | #[cfg (not(target_os = "vita" ))] |
| 87 | Ttou = c::SIGTTOU, |
| 88 | /// `SIGURG` |
| 89 | #[cfg (not(target_os = "vita" ))] |
| 90 | Urg = c::SIGURG, |
| 91 | /// `SIGXCPU` |
| 92 | #[cfg (not(target_os = "vita" ))] |
| 93 | Xcpu = c::SIGXCPU, |
| 94 | /// `SIGXFSZ` |
| 95 | #[cfg (not(target_os = "vita" ))] |
| 96 | Xfsz = c::SIGXFSZ, |
| 97 | /// `SIGVTALRM` |
| 98 | #[cfg (not(target_os = "vita" ))] |
| 99 | #[doc (alias = "Vtalrm" )] |
| 100 | Vtalarm = c::SIGVTALRM, |
| 101 | /// `SIGPROF` |
| 102 | #[cfg (not(target_os = "vita" ))] |
| 103 | Prof = c::SIGPROF, |
| 104 | /// `SIGWINCH` |
| 105 | #[cfg (not(target_os = "vita" ))] |
| 106 | Winch = c::SIGWINCH, |
| 107 | /// `SIGIO`, aka `SIGPOLL` |
| 108 | #[doc (alias = "Poll" )] |
| 109 | #[cfg (not(any(target_os = "haiku" , target_os = "vita" )))] |
| 110 | Io = c::SIGIO, |
| 111 | /// `SIGPWR` |
| 112 | #[cfg (not(any(bsd, target_os = "haiku" , target_os = "hurd" , target_os = "vita" )))] |
| 113 | #[doc (alias = "Pwr" )] |
| 114 | Power = c::SIGPWR, |
| 115 | /// `SIGSYS`, aka `SIGUNUSED` |
| 116 | #[doc (alias = "Unused" )] |
| 117 | Sys = c::SIGSYS, |
| 118 | /// `SIGEMT` |
| 119 | #[cfg (any( |
| 120 | bsd, |
| 121 | solarish, |
| 122 | target_os = "aix" , |
| 123 | target_os = "hermit" , |
| 124 | all( |
| 125 | linux_kernel, |
| 126 | any( |
| 127 | target_arch = "mips" , |
| 128 | target_arch = "mips32r6" , |
| 129 | target_arch = "mips64" , |
| 130 | target_arch = "mips64r6" , |
| 131 | target_arch = "sparc" , |
| 132 | target_arch = "sparc64" |
| 133 | ) |
| 134 | ) |
| 135 | ))] |
| 136 | Emt = c::SIGEMT, |
| 137 | /// `SIGINFO` |
| 138 | #[cfg (bsd)] |
| 139 | Info = c::SIGINFO, |
| 140 | /// `SIGTHR` |
| 141 | #[cfg (target_os = "freebsd" )] |
| 142 | #[doc (alias = "Lwp" )] |
| 143 | Thr = c::SIGTHR, |
| 144 | /// `SIGLIBRT` |
| 145 | #[cfg (target_os = "freebsd" )] |
| 146 | Librt = c::SIGLIBRT, |
| 147 | } |
| 148 | |
| 149 | impl Signal { |
| 150 | /// Convert a raw signal number into a `Signal`, if possible. |
| 151 | pub fn from_raw(sig: c::c_int) -> Option<Self> { |
| 152 | match sig { |
| 153 | c::SIGHUP => Some(Self::Hup), |
| 154 | c::SIGINT => Some(Self::Int), |
| 155 | c::SIGQUIT => Some(Self::Quit), |
| 156 | c::SIGILL => Some(Self::Ill), |
| 157 | c::SIGTRAP => Some(Self::Trap), |
| 158 | c::SIGABRT => Some(Self::Abort), |
| 159 | c::SIGBUS => Some(Self::Bus), |
| 160 | c::SIGFPE => Some(Self::Fpe), |
| 161 | c::SIGKILL => Some(Self::Kill), |
| 162 | #[cfg (not(target_os = "vita" ))] |
| 163 | c::SIGUSR1 => Some(Self::Usr1), |
| 164 | c::SIGSEGV => Some(Self::Segv), |
| 165 | #[cfg (not(target_os = "vita" ))] |
| 166 | c::SIGUSR2 => Some(Self::Usr2), |
| 167 | c::SIGPIPE => Some(Self::Pipe), |
| 168 | c::SIGALRM => Some(Self::Alarm), |
| 169 | c::SIGTERM => Some(Self::Term), |
| 170 | #[cfg (not(any( |
| 171 | bsd, |
| 172 | solarish, |
| 173 | target_os = "aix" , |
| 174 | target_os = "haiku" , |
| 175 | target_os = "hurd" , |
| 176 | target_os = "nto" , |
| 177 | target_os = "vita" , |
| 178 | all( |
| 179 | linux_kernel, |
| 180 | any( |
| 181 | target_arch = "mips" , |
| 182 | target_arch = "mips32r6" , |
| 183 | target_arch = "mips64" , |
| 184 | target_arch = "mips64r6" , |
| 185 | target_arch = "sparc" , |
| 186 | target_arch = "sparc64" |
| 187 | ), |
| 188 | ) |
| 189 | )))] |
| 190 | c::SIGSTKFLT => Some(Self::Stkflt), |
| 191 | #[cfg (not(target_os = "vita" ))] |
| 192 | c::SIGCHLD => Some(Self::Child), |
| 193 | #[cfg (not(target_os = "vita" ))] |
| 194 | c::SIGCONT => Some(Self::Cont), |
| 195 | #[cfg (not(target_os = "vita" ))] |
| 196 | c::SIGSTOP => Some(Self::Stop), |
| 197 | #[cfg (not(target_os = "vita" ))] |
| 198 | c::SIGTSTP => Some(Self::Tstp), |
| 199 | #[cfg (not(target_os = "vita" ))] |
| 200 | c::SIGTTIN => Some(Self::Ttin), |
| 201 | #[cfg (not(target_os = "vita" ))] |
| 202 | c::SIGTTOU => Some(Self::Ttou), |
| 203 | #[cfg (not(target_os = "vita" ))] |
| 204 | c::SIGURG => Some(Self::Urg), |
| 205 | #[cfg (not(target_os = "vita" ))] |
| 206 | c::SIGXCPU => Some(Self::Xcpu), |
| 207 | #[cfg (not(target_os = "vita" ))] |
| 208 | c::SIGXFSZ => Some(Self::Xfsz), |
| 209 | #[cfg (not(target_os = "vita" ))] |
| 210 | c::SIGVTALRM => Some(Self::Vtalarm), |
| 211 | #[cfg (not(target_os = "vita" ))] |
| 212 | c::SIGPROF => Some(Self::Prof), |
| 213 | #[cfg (not(target_os = "vita" ))] |
| 214 | c::SIGWINCH => Some(Self::Winch), |
| 215 | #[cfg (not(any(target_os = "haiku" , target_os = "vita" )))] |
| 216 | c::SIGIO => Some(Self::Io), |
| 217 | #[cfg (not(any(bsd, target_os = "haiku" , target_os = "hurd" , target_os = "vita" )))] |
| 218 | c::SIGPWR => Some(Self::Power), |
| 219 | c::SIGSYS => Some(Self::Sys), |
| 220 | #[cfg (any( |
| 221 | bsd, |
| 222 | solarish, |
| 223 | target_os = "aix" , |
| 224 | target_os = "hermit" , |
| 225 | all( |
| 226 | linux_kernel, |
| 227 | any( |
| 228 | target_arch = "mips" , |
| 229 | target_arch = "mips32r6" , |
| 230 | target_arch = "mips64" , |
| 231 | target_arch = "mips64r6" , |
| 232 | target_arch = "sparc" , |
| 233 | target_arch = "sparc64" |
| 234 | ) |
| 235 | ) |
| 236 | ))] |
| 237 | c::SIGEMT => Some(Self::Emt), |
| 238 | #[cfg (bsd)] |
| 239 | c::SIGINFO => Some(Self::Info), |
| 240 | #[cfg (target_os = "freebsd" )] |
| 241 | c::SIGTHR => Some(Self::Thr), |
| 242 | #[cfg (target_os = "freebsd" )] |
| 243 | c::SIGLIBRT => Some(Self::Librt), |
| 244 | _ => None, |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | #[test ] |
| 250 | fn test_sizes() { |
| 251 | assert_eq_size!(Signal, c::c_int); |
| 252 | } |
| 253 | |