proc_exit/bash.rs
1//! Bash [exit codes](https://tldp.org/LDP/abs/html/exitcodes.html)
2
3/// Convert [`std::io::ErrorKind`] to a [`Code`][crate::Code]
4#[inline]
5pub fn io_to_signal(kind: std::io::ErrorKind) -> Option<crate::Code> {
6 match kind {
7 std::io::ErrorKind::BrokenPipe => Some(SIGPIPE),
8 std::io::ErrorKind::TimedOut => Some(SIGALRM),
9 std::io::ErrorKind::Interrupted => Some(SIGINT),
10 _ => None,
11 }
12}
13
14/// Command line usage error
15///
16/// While bash generally documents this as "Misuse of shell builtins (according to Bash
17/// documentation)", it is more broadly interpreted as a general usage error.
18pub const USAGE: crate::Code = crate::Code::new(2);
19
20/// Command was found but is not executable by the shell.
21pub const NOT_EXECUTABLE: crate::Code = crate::Code::new(126);
22
23/// Usually indicates that the command was not found by the shell, or that
24/// the command is found but that a library it requires is not found.
25pub const NOT_FOUND: crate::Code = crate::Code::new(127);
26
27/// Usually indicates that the command was not found by the shell, or that
28/// the command is found but that a library it requires is not found.
29pub const INVALID_EXIT: crate::Code = crate::Code::new(128);
30
31/// Exit status out of range
32///
33/// `exit` takes only integer args in the range 0 - 255
34pub const STATUS_OUT_OF_RANGE: crate::Code = crate::Code::new(255);
35
36const SIGBASE: i32 = 128;
37
38/// The `SIGHUP` signal is sent to a process when its controlling terminal
39/// is closed.
40pub const SIGHUP: crate::Code = crate::Code::new(SIGBASE + 1);
41
42/// The `SIGINT` signal is sent to a process by its controlling terminal
43/// when a user wishes to interrupt the process.
44pub const SIGINT: crate::Code = crate::Code::new(SIGBASE + 2);
45
46/// The `SIGQUIT` signal is sent to a process by its controlling terminal
47/// when a user quit from keyboard (Ctrl-\. or, Ctrl-4 or, on the virtual console, the `SysRq` key)
48pub const SIGQUIT: crate::Code = crate::Code::new(SIGBASE + 3);
49
50/// The `SIGILL` signal is sent to a process by its controlling terminal
51/// when an illegal instruction is encountered
52pub const SIGILL: crate::Code = crate::Code::new(SIGBASE + 4);
53
54/// The `SIGTRAP` signal is sent to a process by its controlling terminal
55/// when there is a trace/breakpoint trap
56pub const SIGTRAP: crate::Code = crate::Code::new(SIGBASE + 5);
57
58/// The `SIGABRT` signal is sent to a process by its controlling terminal
59/// when process abort signal
60pub const SIGABRT: crate::Code = crate::Code::new(SIGBASE + 6);
61
62/// The `SIGFPE` signal is sent to a process by its controlling terminal
63/// when there is an erroneous arithmetic operation
64pub const SIGFPE: crate::Code = crate::Code::new(SIGBASE + 8);
65
66/// The `SIGKILL` signal is sent to a process to cause it to terminate
67/// immediately. In contrast to `SIGTERM` and `SIGINT`, this signal cannot
68/// be caught or ignored, and the receiving process cannot perform any
69/// clean-up upon receiving this signal.
70pub const SIGKILL: crate::Code = crate::Code::new(SIGBASE + 9);
71
72/// The `SIGSEGV` signal is sent to a process on invalid memory reference
73pub const SIGSEGV: crate::Code = crate::Code::new(SIGBASE + 11);
74
75/// The `SIGPIPE` signal is sent to a process when it attempts to write to
76/// a pipe without a process connected to the other end.
77pub const SIGPIPE: crate::Code = crate::Code::new(SIGBASE + 13);
78
79/// The `SIGALRM` signal is sent to a process when the time limit specified
80/// in a call to a preceding alarm setting function (such as `setitimer`)
81/// elapses.
82pub const SIGALRM: crate::Code = crate::Code::new(SIGBASE + 14);
83
84/// The `SIGTERM` signal is sent to a process to request its termination.
85/// Unlike the `SIGKILL` signal, it can be caught and interpreted or
86/// ignored by the process.
87pub const SIGTERM: crate::Code = crate::Code::new(SIGBASE + 15);