Contents of /trunk/mkinitrd-magellan/busybox/libbb/u_signal_names.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1572 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1572 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Signal name/number conversion routines. |
4 | * |
5 | * Copyright 2006 Rob Landley <rob@landley.net> |
6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ |
9 | |
10 | #include "libbb.h" |
11 | |
12 | static const struct signal_name { |
13 | int number; |
14 | char name[5]; |
15 | } signals[] = { |
16 | // SUSv3 says kill must support these, and specifies the numerical values, |
17 | // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html |
18 | // TODO: "[SIG]EXIT" shouldn't work for kill, right? |
19 | {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"}, {6, "ABRT"}, {9, "KILL"}, |
20 | {14, "ALRM"}, {15, "TERM"}, |
21 | // And Posix adds the following: |
22 | {SIGILL, "ILL"}, {SIGTRAP, "TRAP"}, {SIGFPE, "FPE"}, {SIGUSR1, "USR1"}, |
23 | {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"}, |
24 | {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"}, |
25 | {SIGTTOU, "TTOU"} |
26 | }; |
27 | |
28 | // Convert signal name to number. |
29 | |
30 | int get_signum(const char *name) |
31 | { |
32 | int i; |
33 | |
34 | i = bb_strtou(name, NULL, 10); |
35 | if (!errno) return i; |
36 | for (i = 0; i < sizeof(signals) / sizeof(struct signal_name); i++) |
37 | if (strcasecmp(name, signals[i].name) == 0 |
38 | || (strncasecmp(name, "SIG", 3) == 0 |
39 | && strcasecmp(&name[3], signals[i].name) == 0)) |
40 | return signals[i].number; |
41 | return -1; |
42 | } |
43 | |
44 | // Convert signal number to name |
45 | |
46 | const char *get_signame(int number) |
47 | { |
48 | int i; |
49 | static char buf[8]; |
50 | |
51 | for (i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) { |
52 | if (number == signals[i].number) { |
53 | return signals[i].name; |
54 | } |
55 | } |
56 | |
57 | itoa_to_buf(number, buf, 8); |
58 | return buf; |
59 | } |