diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-01 20:07:29 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-01 20:07:29 +0000 |
commit | dcf4de20a1904bb31d498b6cc999a37f20b2783d (patch) | |
tree | 9c4c939bb250f37bd4f405b74723824cde1e8d7b /libbb/u_signal_names.c | |
parent | f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b (diff) | |
download | busybox-w32-dcf4de20a1904bb31d498b6cc999a37f20b2783d.tar.gz busybox-w32-dcf4de20a1904bb31d498b6cc999a37f20b2783d.tar.bz2 busybox-w32-dcf4de20a1904bb31d498b6cc999a37f20b2783d.zip |
test: code size saving, no logic changes
ps: fix warning, make a bit smaller
kill -l: make smaller & know much more signals
function old new delta
get_signum 121 153 +32
kill_main 826 843 +17
get_signame 44 36 -8
signals 252 224 -28
.rodata 131955 131923 -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 49/-68) Total: -19 bytes
Diffstat (limited to 'libbb/u_signal_names.c')
-rw-r--r-- | libbb/u_signal_names.c | 148 |
1 files changed, 126 insertions, 22 deletions
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index 52861d405..dc4c0b237 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c | |||
@@ -9,20 +9,111 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | static const struct signal_name { | 12 | static const char signals[32][7] = { |
13 | int number; | ||
14 | char name[5]; | ||
15 | } signals[] = { | ||
16 | // SUSv3 says kill must support these, and specifies the numerical values, | 13 | // SUSv3 says kill must support these, and specifies the numerical values, |
17 | // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html | 14 | // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html |
18 | // TODO: "[SIG]EXIT" shouldn't work for kill, right? | 15 | // TODO: "[SIG]EXIT" shouldn't work for kill, right? |
19 | {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"}, {6, "ABRT"}, {9, "KILL"}, | 16 | // {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"}, |
20 | {14, "ALRM"}, {15, "TERM"}, | 17 | // {6, "ABRT"}, {9, "KILL"}, {14, "ALRM"}, {15, "TERM"} |
21 | // And Posix adds the following: | 18 | // And Posix adds the following: |
22 | {SIGILL, "ILL"}, {SIGTRAP, "TRAP"}, {SIGFPE, "FPE"}, {SIGUSR1, "USR1"}, | 19 | // {SIGILL, "ILL"}, {SIGTRAP, "TRAP"}, {SIGFPE, "FPE"}, {SIGUSR1, "USR1"}, |
23 | {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"}, | 20 | // {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"}, |
24 | {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"}, | 21 | // {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"}, |
25 | {SIGTTOU, "TTOU"} | 22 | // {SIGTTOU, "TTOU"} |
23 | [0] = "EXIT", | ||
24 | #ifdef SIGHUP | ||
25 | [SIGHUP ] = "HUP", | ||
26 | #endif | ||
27 | #ifdef SIGINT | ||
28 | [SIGINT ] = "INT", | ||
29 | #endif | ||
30 | #ifdef SIGQUIT | ||
31 | [SIGQUIT ] = "QUIT", | ||
32 | #endif | ||
33 | #ifdef SIGILL | ||
34 | [SIGILL ] = "ILL", | ||
35 | #endif | ||
36 | #ifdef SIGTRAP | ||
37 | [SIGTRAP ] = "TRAP", | ||
38 | #endif | ||
39 | #ifdef SIGABRT | ||
40 | [SIGABRT ] = "ABRT", | ||
41 | #endif | ||
42 | #ifdef SIGBUS | ||
43 | [SIGBUS ] = "BUS", | ||
44 | #endif | ||
45 | #ifdef SIGFPE | ||
46 | [SIGFPE ] = "FPE", | ||
47 | #endif | ||
48 | #ifdef SIGKILL | ||
49 | [SIGKILL ] = "KILL", | ||
50 | #endif | ||
51 | #ifdef SIGUSR1 | ||
52 | [SIGUSR1 ] = "USR1", | ||
53 | #endif | ||
54 | #ifdef SIGSEGV | ||
55 | [SIGSEGV ] = "SEGV", | ||
56 | #endif | ||
57 | #ifdef SIGUSR2 | ||
58 | [SIGUSR2 ] = "USR2", | ||
59 | #endif | ||
60 | #ifdef SIGPIPE | ||
61 | [SIGPIPE ] = "PIPE", | ||
62 | #endif | ||
63 | #ifdef SIGALRM | ||
64 | [SIGALRM ] = "ALRM", | ||
65 | #endif | ||
66 | #ifdef SIGTERM | ||
67 | [SIGTERM ] = "TERM", | ||
68 | #endif | ||
69 | #ifdef SIGSTKFLT | ||
70 | [SIGSTKFLT] = "STKFLT", | ||
71 | #endif | ||
72 | #ifdef SIGCHLD | ||
73 | [SIGCHLD ] = "CHLD", | ||
74 | #endif | ||
75 | #ifdef SIGCONT | ||
76 | [SIGCONT ] = "CONT", | ||
77 | #endif | ||
78 | #ifdef SIGSTOP | ||
79 | [SIGSTOP ] = "STOP", | ||
80 | #endif | ||
81 | #ifdef SIGTSTP | ||
82 | [SIGTSTP ] = "TSTP", | ||
83 | #endif | ||
84 | #ifdef SIGTTIN | ||
85 | [SIGTTIN ] = "TTIN", | ||
86 | #endif | ||
87 | #ifdef SIGTTOU | ||
88 | [SIGTTOU ] = "TTOU", | ||
89 | #endif | ||
90 | #ifdef SIGURG | ||
91 | [SIGURG ] = "URG", | ||
92 | #endif | ||
93 | #ifdef SIGXCPU | ||
94 | [SIGXCPU ] = "XCPU", | ||
95 | #endif | ||
96 | #ifdef SIGXFSZ | ||
97 | [SIGXFSZ ] = "XFSZ", | ||
98 | #endif | ||
99 | #ifdef SIGVTALRM | ||
100 | [SIGVTALRM] = "VTALRM", | ||
101 | #endif | ||
102 | #ifdef SIGPROF | ||
103 | [SIGPROF ] = "PROF", | ||
104 | #endif | ||
105 | #ifdef SIGWINCH | ||
106 | [SIGWINCH ] = "WINCH", | ||
107 | #endif | ||
108 | #ifdef SIGPOLL | ||
109 | [SIGPOLL ] = "POLL", | ||
110 | #endif | ||
111 | #ifdef SIGPWR | ||
112 | [SIGPWR ] = "PWR", | ||
113 | #endif | ||
114 | #ifdef SIGSYS | ||
115 | [SIGSYS ] = "SYS", | ||
116 | #endif | ||
26 | }; | 117 | }; |
27 | 118 | ||
28 | // Convert signal name to number. | 119 | // Convert signal name to number. |
@@ -32,12 +123,28 @@ int get_signum(const char *name) | |||
32 | int i; | 123 | int i; |
33 | 124 | ||
34 | i = bb_strtou(name, NULL, 10); | 125 | i = bb_strtou(name, NULL, 10); |
35 | if (!errno) return i; | 126 | if (!errno) |
36 | for (i = 0; i < sizeof(signals) / sizeof(struct signal_name); i++) | 127 | return i; |
37 | if (strcasecmp(name, signals[i].name) == 0 | 128 | if (strncasecmp(name, "SIG", 3) == 0) |
38 | || (strncasecmp(name, "SIG", 3) == 0 | 129 | name += 3; |
39 | && strcasecmp(&name[3], signals[i].name) == 0)) | 130 | for (i = 0; i < sizeof(signals) / sizeof(signals[0]); i++) |
40 | return signals[i].number; | 131 | if (strcasecmp(name, signals[i]) == 0) |
132 | return i; | ||
133 | |||
134 | #if ENABLE_DESKTOP && (defined(SIGIOT) || defined(SIGIO)) | ||
135 | /* These are aliased to other names */ | ||
136 | if ((name[0] | 0x20) == 'i' && (name[1] | 0x20) == 'o') { | ||
137 | #ifdef SIGIO | ||
138 | if (!name[2]) | ||
139 | return SIGIO; | ||
140 | #endif | ||
141 | #ifdef SIGIOT | ||
142 | if ((name[2] | 0x20) == 't' && !name[3]) | ||
143 | return SIGIOT; | ||
144 | #endif | ||
145 | } | ||
146 | #endif | ||
147 | |||
41 | return -1; | 148 | return -1; |
42 | } | 149 | } |
43 | 150 | ||
@@ -45,12 +152,9 @@ int get_signum(const char *name) | |||
45 | 152 | ||
46 | const char *get_signame(int number) | 153 | const char *get_signame(int number) |
47 | { | 154 | { |
48 | int i; | 155 | if ((unsigned)number < sizeof(signals) / sizeof(signals[0])) { |
49 | 156 | if (signals[number][0]) /* if it's not an empty str */ | |
50 | for (i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) { | 157 | return signals[number]; |
51 | if (number == signals[i].number) { | ||
52 | return signals[i].name; | ||
53 | } | ||
54 | } | 158 | } |
55 | 159 | ||
56 | return itoa(number); | 160 | return itoa(number); |