1 /* vi: set sw=4 ts=4: */
3 * Signal name/number conversion routines.
5 * Copyright 2006 Rob Landley <rob@landley.net>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config:config FEATURE_RTMINMAX
11 //config: bool "Support RTMIN[+n] and RTMAX[-n] signal names"
14 //config: Support RTMIN[+n] and RTMAX[-n] signal names
15 //config: in kill, killall etc. This costs ~250 bytes.
19 /* Believe it or not, but some arches have more than 32 SIGs!
20 * HPPA: SIGSTKFLT == 36. */
22 static const char signals[][7] = {
23 // SUSv3 says kill must support these, and specifies the numerical values,
24 // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html
25 // {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"},
26 // {6, "ABRT"}, {9, "KILL"}, {14, "ALRM"}, {15, "TERM"}
27 // And Posix adds the following:
28 // {SIGILL, "ILL"}, {SIGTRAP, "TRAP"}, {SIGFPE, "FPE"}, {SIGUSR1, "USR1"},
29 // {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"},
30 // {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"},
80 [SIGSTKFLT] = "STKFLT",
110 [SIGVTALRM] = "VTALRM",
116 [SIGWINCH ] = "WINCH",
129 // Convert signal name to number.
131 int FAST_FUNC get_signum(const char *name)
135 i = bb_strtou(name, NULL, 10);
138 if (strncasecmp(name, "SIG", 3) == 0)
140 for (i = 0; i < ARRAY_SIZE(signals); i++)
141 if (strcasecmp(name, signals[i]) == 0)
145 # if defined(SIGIOT) || defined(SIGIO)
146 /* SIGIO[T] are aliased to other names,
147 * thus cannot be stored in the signals[] array.
148 * Need special code to recognize them */
149 if ((name[0] | 0x20) == 'i' && (name[1] | 0x20) == 'o') {
155 if ((name[2] | 0x20) == 't' && !name[3])
162 #if ENABLE_FEATURE_RTMINMAX
163 # if defined(SIGRTMIN) && defined(SIGRTMAX)
164 /* libc may use some rt sigs for pthreads and therefore "remap" SIGRTMIN/MAX,
165 * but we want to use "raw" SIGRTMIN/MAX. Underscored names, if exist, provide
166 * them. If they don't exist, fall back to non-underscored ones: */
167 # if !defined(__SIGRTMIN)
168 # define __SIGRTMIN SIGRTMIN
170 # if !defined(__SIGRTMAX)
171 # define __SIGRTMAX SIGRTMAX
173 if (strncasecmp(name, "RTMIN", 5) == 0) {
176 if (name[5] == '+') {
177 i = bb_strtou(name + 6, NULL, 10);
178 if (!errno && i <= __SIGRTMAX - __SIGRTMIN)
179 return __SIGRTMIN + i;
182 else if (strncasecmp(name, "RTMAX", 5) == 0) {
185 if (name[5] == '-') {
186 i = bb_strtou(name + 6, NULL, 10);
187 if (!errno && i <= __SIGRTMAX - __SIGRTMIN)
188 return __SIGRTMAX - i;
197 // Convert signal number to name
199 const char* FAST_FUNC get_signame(int number)
201 if ((unsigned)number < ARRAY_SIZE(signals)) {
202 if (signals[number][0]) /* if it's not an empty str */
203 return signals[number];
210 // Print the whole signal list
212 void FAST_FUNC print_signames(void)
216 for (signo = 1; signo < ARRAY_SIZE(signals); signo++) {
217 const char *name = signals[signo];