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 tarball for details.
12 /* Believe it or not, but some arches have more than 32 SIGs!
13 * HPPA: SIGSTKFLT == 36. */
15 static const char signals[][7] = {
16 // SUSv3 says kill must support these, and specifies the numerical values,
17 // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html
18 // {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"},
19 // {6, "ABRT"}, {9, "KILL"}, {14, "ALRM"}, {15, "TERM"}
20 // And Posix adds the following:
21 // {SIGILL, "ILL"}, {SIGTRAP, "TRAP"}, {SIGFPE, "FPE"}, {SIGUSR1, "USR1"},
22 // {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"},
23 // {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"},
73 [SIGSTKFLT] = "STKFLT",
103 [SIGVTALRM] = "VTALRM",
109 [SIGWINCH ] = "WINCH",
122 // Convert signal name to number.
124 int FAST_FUNC get_signum(const char *name)
128 i = bb_strtou(name, NULL, 10);
131 if (strncasecmp(name, "SIG", 3) == 0)
133 for (i = 0; i < ARRAY_SIZE(signals); i++)
134 if (strcasecmp(name, signals[i]) == 0)
137 #if ENABLE_DESKTOP && (defined(SIGIOT) || defined(SIGIO))
138 /* SIGIO[T] are aliased to other names,
139 * thus cannot be stored in the signals[] array.
140 * Need special code to recognize them */
141 if ((name[0] | 0x20) == 'i' && (name[1] | 0x20) == 'o') {
147 if ((name[2] | 0x20) == 't' && !name[3])
156 // Convert signal number to name
158 const char* FAST_FUNC get_signame(int number)
160 if ((unsigned)number < ARRAY_SIZE(signals)) {
161 if (signals[number][0]) /* if it's not an empty str */
162 return signals[number];
169 // Print the whole signal list
171 void FAST_FUNC print_signames(void)
175 for (signo = 1; signo < ARRAY_SIZE(signals); signo++) {
176 const char *name = signals[signo];