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-07-12 19:17:55 +00:00
|
|
|
static struct signal_name {
|
|
|
|
char *name;
|
2001-08-02 05:18:55 +00:00
|
|
|
int number;
|
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
|
|
|
|
{"0", 0}, {"HUP", 1}, {"INT", 2}, {"QUIT", 3}, {"ABRT", 6}, {"KILL", 9},
|
2006-09-17 16:28:10 +00:00
|
|
|
{"ALRM", 14}, {"TERM", 15},
|
2006-07-12 19:17:55 +00:00
|
|
|
// And Posix adds the following:
|
|
|
|
{"ILL", SIGILL}, {"TRAP", SIGTRAP}, {"FPE", SIGFPE}, {"USR1", SIGUSR1},
|
2006-09-17 16:28:10 +00:00
|
|
|
{"SEGV", SIGSEGV}, {"USR2", SIGUSR2}, {"PIPE", SIGPIPE}, {"CHLD", SIGCHLD},
|
|
|
|
{"CONT", SIGCONT}, {"STOP", SIGSTOP}, {"TSTP", SIGTSTP}, {"TTIN", SIGTTIN},
|
|
|
|
{"TTOU", SIGTTOU}
|
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-07-12 19:17:55 +00:00
|
|
|
int get_signum(char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = atoi(name);
|
|
|
|
if(i) return i;
|
|
|
|
for(i=0; i < sizeof(signals) / sizeof(struct signal_name); i++)
|
|
|
|
if (!strcasecmp(signals[i].name, name) ||
|
|
|
|
(!strncasecmp(signals[i].name, "SIG", 3)
|
|
|
|
&& !strcasecmp(signals[i].name+3, signals[i].name)))
|
|
|
|
return signals[i].number;
|
|
|
|
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-07-12 19:17:55 +00:00
|
|
|
char *get_signame(int number)
|
2001-08-02 05:18:55 +00:00
|
|
|
{
|
2006-07-12 19:17:55 +00:00
|
|
|
int i;
|
|
|
|
static char buf[8];
|
|
|
|
|
|
|
|
itoa_to_buf(number, buf, 8);
|
|
|
|
for (i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) {
|
|
|
|
if (number == signals[i].number) {
|
|
|
|
sprintf("SIG%s", signals[i].name);
|
|
|
|
break;
|
2001-08-02 05:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-12 19:17:55 +00:00
|
|
|
|
|
|
|
return buf;
|
2001-08-02 05:18:55 +00:00
|
|
|
}
|