2001-10-24 05:00:29 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2006-07-12 19:17:55 +00:00
|
|
|
* Signal name/number conversion routines.
|
2001-10-24 05:00:29 +00:00
|
|
|
*
|
2006-07-12 19:17:55 +00:00
|
|
|
* Copyright 2006 Rob Landley <rob@landley.net>
|
2001-10-24 05:00:29 +00:00
|
|
|
*
|
2006-04-03 16:39:31 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2001-10-24 05:00:29 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-03 16:39:31 +00:00
|
|
|
#include "libbb.h"
|
|
|
|
|
2007-05-01 20:07:29 +00:00
|
|
|
static const char signals[32][7] = {
|
2006-07-12 19:17:55 +00:00
|
|
|
// SUSv3 says kill must support these, and specifies the numerical values,
|
|
|
|
// http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html
|
2006-12-23 01:06:21 +00:00
|
|
|
// TODO: "[SIG]EXIT" shouldn't work for kill, right?
|
2007-05-01 20:07:29 +00:00
|
|
|
// {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"},
|
|
|
|
// {6, "ABRT"}, {9, "KILL"}, {14, "ALRM"}, {15, "TERM"}
|
2006-07-12 19:17:55 +00:00
|
|
|
// And Posix adds the following:
|
2007-05-01 20:07:29 +00:00
|
|
|
// {SIGILL, "ILL"}, {SIGTRAP, "TRAP"}, {SIGFPE, "FPE"}, {SIGUSR1, "USR1"},
|
|
|
|
// {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"},
|
|
|
|
// {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"},
|
|
|
|
// {SIGTTOU, "TTOU"}
|
|
|
|
[0] = "EXIT",
|
|
|
|
#ifdef SIGHUP
|
|
|
|
[SIGHUP ] = "HUP",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
|
|
|
[SIGINT ] = "INT",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
[SIGQUIT ] = "QUIT",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
|
|
|
[SIGILL ] = "ILL",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
|
|
|
[SIGTRAP ] = "TRAP",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
|
|
|
[SIGABRT ] = "ABRT",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
|
|
|
[SIGBUS ] = "BUS",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
|
|
|
[SIGFPE ] = "FPE",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
|
|
|
[SIGKILL ] = "KILL",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
|
|
|
[SIGUSR1 ] = "USR1",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
[SIGSEGV ] = "SEGV",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
|
|
|
[SIGUSR2 ] = "USR2",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
[SIGPIPE ] = "PIPE",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
|
|
|
[SIGALRM ] = "ALRM",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
|
|
|
[SIGTERM ] = "TERM",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSTKFLT
|
|
|
|
[SIGSTKFLT] = "STKFLT",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
|
|
|
[SIGCHLD ] = "CHLD",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
|
|
|
[SIGCONT ] = "CONT",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
|
|
|
[SIGSTOP ] = "STOP",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
|
|
|
[SIGTSTP ] = "TSTP",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
|
|
|
[SIGTTIN ] = "TTIN",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
|
|
|
[SIGTTOU ] = "TTOU",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
|
|
|
[SIGURG ] = "URG",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
|
|
|
[SIGXCPU ] = "XCPU",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
|
|
|
[SIGXFSZ ] = "XFSZ",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
|
|
|
[SIGVTALRM] = "VTALRM",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
|
|
|
[SIGPROF ] = "PROF",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
[SIGWINCH ] = "WINCH",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
|
|
|
[SIGPOLL ] = "POLL",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
|
|
|
[SIGPWR ] = "PWR",
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
|
|
|
[SIGSYS ] = "SYS",
|
|
|
|
#endif
|
2001-08-02 05:18:55 +00:00
|
|
|
};
|
|
|
|
|
2006-07-12 19:17:55 +00:00
|
|
|
// Convert signal name to number.
|
2001-08-02 05:18:55 +00:00
|
|
|
|
2006-09-27 14:19:16 +00:00
|
|
|
int get_signum(const char *name)
|
2006-07-12 19:17:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-12-23 01:06:21 +00:00
|
|
|
i = bb_strtou(name, NULL, 10);
|
2007-05-01 20:07:29 +00:00
|
|
|
if (!errno)
|
|
|
|
return i;
|
|
|
|
if (strncasecmp(name, "SIG", 3) == 0)
|
|
|
|
name += 3;
|
2007-06-25 10:55:35 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(signals); i++)
|
2007-05-01 20:07:29 +00:00
|
|
|
if (strcasecmp(name, signals[i]) == 0)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
#if ENABLE_DESKTOP && (defined(SIGIOT) || defined(SIGIO))
|
|
|
|
/* These are aliased to other names */
|
|
|
|
if ((name[0] | 0x20) == 'i' && (name[1] | 0x20) == 'o') {
|
|
|
|
#ifdef SIGIO
|
|
|
|
if (!name[2])
|
|
|
|
return SIGIO;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGIOT
|
|
|
|
if ((name[2] | 0x20) == 't' && !name[3])
|
|
|
|
return SIGIOT;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-07-12 19:17:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2001-08-02 05:18:55 +00:00
|
|
|
|
2006-07-12 19:17:55 +00:00
|
|
|
// Convert signal number to name
|
2001-08-02 05:18:55 +00:00
|
|
|
|
2006-09-27 14:19:16 +00:00
|
|
|
const char *get_signame(int number)
|
2001-08-02 05:18:55 +00:00
|
|
|
{
|
2007-06-25 10:55:35 +00:00
|
|
|
if ((unsigned)number < ARRAY_SIZE(signals)) {
|
2007-05-01 20:07:29 +00:00
|
|
|
if (signals[number][0]) /* if it's not an empty str */
|
|
|
|
return signals[number];
|
2001-08-02 05:18:55 +00:00
|
|
|
}
|
2006-07-12 19:17:55 +00:00
|
|
|
|
2007-03-14 21:56:51 +00:00
|
|
|
return itoa(number);
|
2001-08-02 05:18:55 +00:00
|
|
|
}
|
2007-09-29 22:26:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Print the whole signal list
|
|
|
|
|
2007-09-30 16:32:01 +00:00
|
|
|
void print_signames(void)
|
2007-09-29 22:26:01 +00:00
|
|
|
{
|
|
|
|
int signo;
|
|
|
|
|
|
|
|
for (signo = 1; signo < ARRAY_SIZE(signals); signo++) {
|
|
|
|
const char *name = signals[signo];
|
|
|
|
if (name[0])
|
|
|
|
puts(name);
|
|
|
|
}
|
|
|
|
}
|