summaryrefslogtreecommitdiff
path: root/misc-utils/kill.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2006-12-07 00:25:37 +0100
committerKarel Zak <kzak@redhat.com>2006-12-07 00:25:37 +0100
commit5c36a0eb7cdb0360f9afd5d747c321f423b35984 (patch)
tree147599a77eaff2b5fbc0d389e89d2b51602326c0 /misc-utils/kill.c
parent2b6fc908bc368b540845a313c3b8a867c5ad9a42 (diff)
downloadutil-linux-old-5c36a0eb7cdb0360f9afd5d747c321f423b35984.tar.gz
Imported from util-linux-2.9i tarball.
Diffstat (limited to 'misc-utils/kill.c')
-rw-r--r--misc-utils/kill.c130
1 files changed, 106 insertions, 24 deletions
diff --git a/misc-utils/kill.c b/misc-utils/kill.c
index 85911211..62993813 100644
--- a/misc-utils/kill.c
+++ b/misc-utils/kill.c
@@ -43,20 +43,91 @@
#include <unistd.h>
#include <signal.h>
-#ifdef __linux__
-/*
- * sys_signame -- an ordered list of signals.
- * lifted from /usr/include/linux/signal.h
- * this particular order is only correct for linux.
- * this is _not_ portable.
- */
-char *sys_signame[NSIG] = {
- "zero", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", "UNUSED",
- "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM",
- "STKFLT","CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "IO",
- "XCPU", "XFSZ", "VTALRM","PROF", "WINCH", NULL
-};
+#define SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+struct signv {
+ char *name;
+ int val;
+} sys_signame[] = {
+ /* POSIX signals */
+ { "HUP", SIGHUP }, /* 1 */
+ { "INT", SIGINT }, /* 2 */
+ { "QUIT", SIGQUIT }, /* 3 */
+ { "ILL", SIGILL }, /* 4 */
+ { "ABRT", SIGABRT }, /* 6 */
+ { "FPE", SIGFPE }, /* 8 */
+ { "KILL", SIGKILL }, /* 9 */
+ { "SEGV", SIGSEGV }, /* 11 */
+ { "PIPE", SIGPIPE }, /* 13 */
+ { "ALRM", SIGALRM }, /* 14 */
+ { "TERM", SIGTERM }, /* 15 */
+ { "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */
+ { "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */
+ { "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */
+ { "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */
+ { "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */
+ { "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */
+ { "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */
+ { "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */
+ /* Miscellaneous other signals */
+#ifdef SIGTRAP
+ { "TRAP", SIGTRAP }, /* 5 */
+#endif
+#ifdef SIGIOT
+ { "IOT", SIGIOT }, /* 6, same as SIGABRT */
+#endif
+#ifdef SIGEMT
+ { "EMT", SIGEMT }, /* 7 (mips,alpha,sparc*) */
+#endif
+#ifdef SIGBUS
+ { "BUS", SIGBUS }, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */
+#endif
+#ifdef SIGSYS
+ { "SYS", SIGSYS }, /* 12 (mips,alpha,sparc*) */
+#endif
+#ifdef SIGSTKFLT
+ { "STKFLT", SIGSTKFLT }, /* 16 (arm,i386,m68k,ppc) */
+#endif
+#ifdef SIGURG
+ { "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */
+#endif
+#ifdef SIGIO
+ { "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */
+#endif
+#ifdef SIGPOLL
+ { "POLL", SIGPOLL }, /* same as SIGIO */
+#endif
+#ifdef SIGCLD
+ { "CLD", SIGCLD }, /* same as SIGCHLD (mips) */
+#endif
+#ifdef SIGXCPU
+ { "XCPU", SIGXCPU }, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */
#endif
+#ifdef SIGXFSZ
+ { "XFSZ", SIGXFSZ }, /* 25 (arm,i386,m68k,ppc,alpha,sparc*), 31 (mips) */
+#endif
+#ifdef SIGVTALRM
+ { "VTALRM", SIGVTALRM }, /* 26 (arm,i386,m68k,ppc,alpha,sparc*), 28 (mips) */
+#endif
+#ifdef SIGPROF
+ { "PROF", SIGPROF }, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */
+#endif
+#ifdef SIGPWR
+ { "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */
+#endif
+#ifdef SIGINFO
+ { "INFO", SIGINFO }, /* 29 (alpha) */
+#endif
+#ifdef SIGLOST
+ { "LOST", SIGLOST }, /* 29 (arm,i386,m68k,ppc,sparc*) */
+#endif
+#ifdef SIGWINCH
+ { "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */
+#endif
+#ifdef SIGUNUSED
+ { "UNUSED", SIGUNUSED }, /* 31 (arm,i386,m68k,ppc) */
+#endif
+};
int main (int argc, char *argv[]);
extern char *mybasename(char *);
@@ -197,9 +268,9 @@ int signame_to_signum (char *sig)
if (! strncasecmp (sig, "sig", 3))
sig += 3;
- for (n = 1; (n < NSIG) && (sys_signame[n] != NULL); n++) {
- if (! strcasecmp (sys_signame[n], sig))
- return n;
+ for (n = 0; n < SIZE(sys_signame); n++) {
+ if (! strcasecmp (sys_signame[n].name, sig))
+ return sys_signame[n].val;
}
return (-1);
}
@@ -226,22 +297,33 @@ void nosig (char *name)
void printsig (int sig)
{
- printf ("%s\n", sys_signame[sig]);
+ int n;
+
+ for (n = 0; n < SIZE(sys_signame); n++) {
+ if (sys_signame[n].val == sig) {
+ printf ("%s\n", sys_signame[n].name);
+ return;
+ }
+ }
+ printf("%d\n", sig);
}
void printsignals (FILE *fp)
{
- int n;
+ int n, lth;
+ int lpos = 0;
- for (n = 1; (n < NSIG) && (sys_signame[n] != NULL); n++) {
- fputs (sys_signame[n], fp);
- if (n == (NSIG / 2) || n == (NSIG - 1))
+ for (n = 0; n < SIZE(sys_signame); n++) {
+ lth = 1+strlen(sys_signame[n].name);
+ if (lpos+lth > 72) {
fputc ('\n', fp);
- else
+ lpos = 0;
+ } else if (lpos)
fputc (' ', fp);
+ lpos += lth;
+ fputs (sys_signame[n].name, fp);
}
- if (n < (NSIG - 1))
- fputc ('\n', fp);
+ fputc ('\n', fp);
}
int usage (int status)