devela/sys/os/linux/consts/
signal.rs

1// devela::sys::os::linux::consts::signal
2//
3
4#![allow(non_camel_case_types)]
5
6use core::ffi::c_int;
7
8/// Linux flag constants for [`LinuxSigaction`][crate::sys::os::linux::LinuxSigaction].
9#[allow(non_camel_case_types)]
10pub struct LINUX_SIGACTION;
11
12/// Linux standard signals constants.
13///
14/// Each signal has a current disposition, which determines how the process
15/// behaves when it is delivered the signal.
16///
17/// - `Term`:   Default action is to terminate the process.
18/// - `Ign`:    Default action is to ignore the signal.
19/// - `Core`:   Default action is to terminate the process and dump core (see core(5)).
20/// - `Stop`:   Default action is to stop the process.
21/// - `Cont`:   Default action is to continue the process if it is currently stopped.
22///
23/// The signals [`SIGKILL`] and [`SIGSTOP`] cannot be caught, blocked, or ignored.
24///
25/// # Info
26/// - <https://man7.org/linux/man-pages/man7/signal.7.html>
27///
28/// [`SIGKILL`]: Self::SIGKILL
29/// [`SIGSTOP`]: Self::SIGSTOP
30#[allow(non_camel_case_types)]
31pub struct LINUX_SIGNAL;
32
33// 36 signals
34impl LINUX_SIGNAL {
35    /// Hangup detected on controlling terminal or death of controlling process.
36    ///
37    /// Default action: `Term`.
38    pub const SIGHUP: c_int = 1;
39
40    /// Interrupt from keyboard.
41    ///
42    /// Default action: `Term`.
43    pub const SIGINT: c_int = 2;
44
45    /// Quit from keyboard.
46    ///
47    /// Default action: `Core`.
48    pub const SIGQUIT: c_int = 3;
49
50    /// Illegal Instruction
51    ///
52    /// Default action: `Core`.
53    pub const SIGILL: c_int = 4;
54
55    /// Trace/breakpoint trap.
56    ///
57    /// Default action: `Core`.
58    pub const SIGTRAP: c_int = 5;
59
60    /// Abort signal from [`abort(3)`].
61    ///
62    /// Default action: `Core`.
63    ///
64    /// [`abort(3)`]: https://man7.org/linux/man-pages/man3/abort.3.html
65    pub const SIGABRT: c_int = 6;
66
67    /// IOT trap. A synonym for [`SIGABRT`][Self::SIGABRT].
68    ///
69    /// Default action:  
70    pub const SIGIOT: c_int = Self::SIGABRT;
71
72    /// Bus error (bad memory access)
73    ///
74    /// Default action: `Core`.
75    pub const SIGBUS: c_int = 7;
76
77    /// Floating-point exception.
78    ///
79    /// Default action: `Core`.
80    pub const SIGFPE: c_int = 8;
81
82    /// Kill signal.
83    ///
84    /// Default action: `Term`.
85    pub const SIGKILL: c_int = 9;
86
87    /// User-defined signal 1.
88    ///
89    /// Default action: `Term`.
90    pub const SIGUSR1: c_int = 10;
91
92    /// Invalid memory reference.
93    ///
94    /// Default action: `Core`.
95    pub const SIGSEGV: c_int = 11;
96
97    /// User-defined signal 2.
98    ///
99    /// Default action: `Term`.
100    pub const SIGUSR2: c_int = 12;
101
102    /// Broken pipe: write to pipe with no readers; see [`pipe(7)`].
103    ///
104    /// Default action: `Term`.
105    ///
106    /// [`pipe(7)`]: https://man7.org/linux/man-pages/man7/pipe.7.html
107    pub const SIGPIPE: c_int = 13;
108
109    /// Timer signal from [`alarm(2)`].
110    ///
111    /// Default action: `Term`.
112    ///
113    /// [`alarm(2)`]: https://man7.org/linux/man-pages/man2/alarm.2.html
114    pub const SIGALRM: c_int = 14;
115
116    /// Termination signal.
117    ///
118    /// Default action: `Term`.
119    pub const SIGTERM: c_int = 15;
120
121    /// Stack fault on coprocessor (unused).
122    ///
123    /// Default action: `Term`.
124    pub const SIGSTKFLT: c_int = 16;
125
126    /// Child stopped or terminated.
127    ///
128    /// Default action: `Ign`.
129    pub const SIGCHLD: c_int = 17;
130
131    /// A synonym for [`SIGCHLD`][Self::SIGCHLD].
132    pub const SIGCLD: c_int = Self::SIGCHLD;
133
134    /// Continue if stopped.
135    ///
136    /// Default action: `Cont`.
137    pub const SIGCONT: c_int = 18;
138
139    /// Stop process.
140    ///
141    /// Default action: `Stop`.
142    pub const SIGSTOP: c_int = 19;
143
144    /// Stop typed at terminal.
145    ///
146    /// Default action: `Stop`.
147    pub const SIGTSTP: c_int = 20;
148
149    /// Terminal input for background process.
150    ///
151    /// Default action: `Stop`.
152    pub const SIGTTIN: c_int = 21;
153
154    /// Terminal output for background process.
155    ///
156    /// Default action: `Stop`.
157    pub const SIGTTOU: c_int = 22;
158
159    /// Urgent condition on socket (4.2BSD).
160    ///
161    /// Default action: `Ign`.
162    pub const SIGURG: c_int = 23;
163
164    /// CPU time limit exceeded (4.2BSD); see [`setrlimit(2)`].
165    ///
166    /// Default action: `Core`.
167    ///
168    /// [`setrlimit(2)`]: https://man7.org/linux/man-pages/man2/setrlimit.2.html
169    pub const SIGXCPU: c_int = 24;
170
171    /// File size limit exceeded (4.2BSD); see [`setrlimit(2)`].
172    ///
173    /// Default action: `Core`.
174    ///
175    /// [`setrlimit(2)`]: https://man7.org/linux/man-pages/man2/setrlimit.2.html
176    pub const SIGXFSZ: c_int = 25;
177
178    /// Virtual alarm clock (4.2BSD).
179    ///
180    /// Default action: `Term`.
181    pub const SIGVTALRM: c_int = 26;
182
183    /// Profiling timer expired.
184    ///
185    /// Default action: `Term`.
186    pub const SIGPROF: c_int = 27;
187
188    /// Window resize signal (4.3BSD, Sun).
189    ///
190    /// Default action: `Ign`.
191    pub const SIGWINCH: c_int = 28;
192
193    /// I/O now possible (4.2BSD).
194    ///
195    /// Default action: `Term`.
196    pub const SIGIO: c_int = 29;
197
198    /// Pollable event (Sys V); synonym for [`SIGIO`][Self::SIGIO].
199    pub const SIGPOLL: c_int = Self::SIGIO;
200
201    /// Power failure (System V).
202    ///
203    /// Default action: `Term`.
204    pub const SIGPWR: c_int = 30;
205
206    /// A synonym for [`SIGPWR`][Self::SIGPWR].
207    pub const SIGINFO: c_int = Self::SIGPWR;
208
209    /// Bad system call (SVr4); see also [`seccomp(2)`].
210    ///
211    /// Default action: `Core`.
212    ///
213    /// [`seccomp(2)`]: https://man7.org/linux/man-pages/man2/seccomp.2.html
214    pub const SIGSYS: c_int = 31;
215
216    /// Synonymous with [`SIGSYS`][Self::SIGSYS].
217    pub const SIGUNUSED: c_int = Self::SIGSYS;
218
219    // /// Emulator trap.
220    // ///
221    // /// Default action: `Term`.
222    // pub const SIGEMT: c_int = ?;
223
224    // /// File lock lost (unused).
225    // ///
226    // /// Default action: `Term`.
227    // pub const SIGLOST: c_int = ?
228}
229
230// 8 flags
231impl LINUX_SIGACTION {
232    /// If signum is [`SIGCHLD`], do not receive notification when child processes
233    /// stop (i.e., when they receive one of [`SIGSTOP`], [`SIGTSTP`], [`SIGTTIN`],
234    /// or [`SIGTTOU`]) or resume (i.e., they receive [`SIGCONT`])
235    /// (see [`wait(2)`]).
236    ///
237    /// This flag is meaningful only when establishing a handler for `SIGCHLD`.
238    ///
239    /// [`SIGCHLD`]: LINUX_SIGNAL::SIGCHLD
240    /// [`SIGSTOP`]: LINUX_SIGNAL::SIGSTOP
241    /// [`SIGTSTP`]: LINUX_SIGNAL::SIGTSTP
242    /// [`SIGTTIN`]: LINUX_SIGNAL::SIGTTIN
243    /// [`SIGTTOU`]: LINUX_SIGNAL::SIGTTOU
244    /// [`SIGCONT`]: LINUX_SIGNAL::SIGCONT
245    /// [`wait(2)`]: https://man7.org/linux/man-pages/man2/wait.2.html
246    pub const SA_NOCLDSTOP: usize = 0x0000_0001;
247
248    /// If signum is [`SIGCHLD`], do not transform children into
249    /// zombies when they terminate.
250    ///
251    /// See also [`waitpid(2)`].
252    ///
253    /// This flag is meaningful only when establishing a handler for `SIGCHLD`,
254    /// or when setting that signal's disposition to [`SIG_DFL`].
255    ///
256    /// (since Linux 2.6)
257    ///
258    /// [`SIGCHLD`]: LINUX_SIGNAL::SIGCHLD
259    /// [`SIG_DFL`]: crate::sys::os::linux::LinuxSigaction::SIG_DFL
260    /// [`waitpid(2)`]: https://man7.org/linux/man-pages/man2/wait.2.html
261    pub const SA_NOCLDWAIT: usize = 0x0000_0002;
262
263    /// If the [`SA_NOCLDWAIT`] flag is set when establishing a handler for
264    /// [`SIGCHLD`], POSIX.1 leaves it unspecified whether a `SIGCHLD` signal is
265    /// generated when a child process terminates.
266    ///
267    /// On Linux, a `SIGCHLD` signal is generated in this case; on some other
268    /// implementations, it is not.
269    ///
270    /// Do not add the signal to the thread's signal mask while the handler is
271    /// executing, unless the signal is specified in act.sa_mask.  Consequently,
272    /// a further instance of the signal may be delivered to the thread while it
273    /// is executing the handler.  This flag is meaningful only when establishing
274    /// a signal handler.
275    ///
276    /// `SA_NOMASK` is an obsolete, nonstandard synonym for this flag.
277    ///
278    /// [`SIGCHLD`]: LINUX_SIGNAL::SIGCHLD
279    /// [`SA_NOCLDWAIT`]: Self::SA_NOCLDWAIT
280    pub const SA_NODEFER: usize = 0x4000_0000;
281
282    /// Call the signal handler on an alternate signal stack provided by
283    /// [`sigaltstack(2)`].
284    ///
285    /// If an alternate stack is not available, the default stack will be used.
286    /// This flag is meaningful only when establishing a signal handler.
287    ///
288    /// [`sigaltstack(2)`]: https://man7.org/linux/man-pages/man2/sigaltstack.2.html
289    pub const SA_ONSTACK: usize = 0x0800_0000;
290
291    /// Restore the signal action to the default upon entry to the signal handler.
292    ///
293    /// This flag is meaningful only when establishing a signal handler.
294    ///
295    /// `SA_ONESHOT` is an obsolete, nonstandard synonym for this flag.
296    pub const SA_RESETHAND: usize = 0x8000_0000;
297
298    /// Provide behavior compatible with BSD signal semantics by making certain
299    /// system calls restartable across signals. This flag is meaningful only
300    /// when establishing a signal handler.  See [`signal(7)`] for a discussion of
301    /// system call restarting.
302    ///
303    /// [`signal(7)`]: https://man7.org/linux/man-pages/man7/signal.7.html
304    pub const SA_RESTART: usize = 0x1000_0000;
305
306    /// Not intended for application use.
307    ///
308    /// This flag is used by C libraries to indicate that the `sa_restorer` field
309    /// contains the address of a "signal trampoline".  See [`sigreturn(2)`] for more
310    /// details.
311    ///
312    /// [`sigreturn(2)`]: https://man7.org/linux/man-pages/man2/sigreturn.2.html
313    pub const SA_RESTORER: usize = 0x0400_0000;
314
315    /// The signal handler takes three arguments, not one.
316    ///
317    /// In this case, `sa_sigaction` should be set instead of `sa_handler`.
318    ///
319    /// This flag is meaningful only when establishing a signal handler.
320    ///
321    /// (since Linux 2.2)
322    pub const SA_SIGINFO: usize = 0x0000_0004;
323}