mirror of
https://github.com/sheumann/hush.git
synced 2024-11-05 06:07:00 +00:00
c9c1a41c58
untangle them: Rewrite u_signal_names() into get_signum() and get_signame(), plus trim the signal list to that required by posix (they can specify the numbers for the rest if they really need them). (This is preparatory cleanup for adding a timeout applet like Roberto Foglietta wants.) Export the itoa (added due to Denis Vlasenko, although it's not quite his preferred implementation) from xfuncs.c so it's actually used, and remove several other redundant implementations of itoa and utoa() in the tree.
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* Signal name/number conversion routines.
|
|
*
|
|
* Copyright 2006 Rob Landley <rob@landley.net>
|
|
*
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
static struct signal_name {
|
|
char *name;
|
|
int number;
|
|
} 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},
|
|
{"ALRM", 14}, {"TERM", 15},
|
|
// And Posix adds the following:
|
|
{"ILL", SIGILL}, {"TRAP", SIGTRAP}, {"FPE", SIGFPE}, {"USR1", SIGUSR1},
|
|
{"SEGV", SIGSEGV}, {"USR2", SIGUSR2}, {"PIPE", SIGPIPE}, {"CHLD", SIGCHLD},
|
|
{"CONT", SIGCONT}, {"STOP", SIGSTOP}, {"TSTP", SIGTSTP}, {"TTIN", SIGTTIN},
|
|
{"TTOU", SIGTTOU}
|
|
};
|
|
|
|
// Convert signal name to number.
|
|
|
|
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;
|
|
}
|
|
|
|
// Convert signal number to name
|
|
|
|
char *get_signame(int number)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
return buf;
|
|
}
|