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