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"
|
|
|
|
|
2006-09-27 14:19:16 +00:00
|
|
|
static const struct signal_name {
|
2001-08-02 05:18:55 +00:00
|
|
|
int number;
|
2006-12-04 15:58:27 +00:00
|
|
|
char name[5];
|
2006-07-12 19:17:55 +00:00
|
|
|
} signals[] = {
|
|
|
|
// 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?
|
|
|
|
{0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"}, {6, "ABRT"}, {9, "KILL"},
|
2006-12-04 15:58:27 +00:00
|
|
|
{14, "ALRM"}, {15, "TERM"},
|
2006-07-12 19:17:55 +00:00
|
|
|
// And Posix adds the following:
|
2006-12-04 15:58:27 +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"}
|
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);
|
|
|
|
if (!errno) return i;
|
2006-12-04 15:58:27 +00:00
|
|
|
for (i = 0; i < sizeof(signals) / sizeof(struct signal_name); i++)
|
2006-12-23 01:06:21 +00:00
|
|
|
if (strcasecmp(name, signals[i].name) == 0
|
|
|
|
|| (strncasecmp(name, "SIG", 3) == 0
|
|
|
|
&& strcasecmp(&name[3], signals[i].name) == 0))
|
|
|
|
return signals[i].number;
|
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
|
|
|
{
|
2006-07-12 19:17:55 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) {
|
|
|
|
if (number == signals[i].number) {
|
2006-09-27 14:19:16 +00:00
|
|
|
return signals[i].name;
|
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
|
|
|
}
|