aboutsummaryrefslogtreecommitdiff
path: root/libbb/u_signal_names.c
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2018-09-12 16:06:36 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-10-31 11:13:55 +0100
commit571e525a141a2de87b9c2ced485745e96418d921 (patch)
tree0841c003d074777df7cb3a0fd7ece733b7bf9988 /libbb/u_signal_names.c
parent93ef5dd640ef41edc72c80fa59c7cc9427b5945b (diff)
downloadbusybox-w32-571e525a141a2de87b9c2ced485745e96418d921.tar.gz
busybox-w32-571e525a141a2de87b9c2ced485745e96418d921.tar.bz2
busybox-w32-571e525a141a2de87b9c2ced485745e96418d921.zip
libbb: optionally honour libc provided SIGRTMIN/SIGRTMAX in get_signum()
When an application documents that it responds such and such to SIGRTMIN+n, that almost always means with respect to the libc-provided SIGRTMIN. Hence I disagree with the "more correct" in commit 7b276fc17594. In any case, this is rather unfortunate: 36 34 (the first shell is bash). We probably can't change default behaviour after 7 years, but at least we can provide a config option. We avoid a little code generation (repeated calls to __libc_current_sigrtmin) by stashing SIGRTMIN/SIGRTMAX in local variables, but it does cost ~50 bytes. The next patch serves as penance for that. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/u_signal_names.c')
-rw-r--r--libbb/u_signal_names.c76
1 files changed, 53 insertions, 23 deletions
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c
index b3038e32d..866ca85fd 100644
--- a/libbb/u_signal_names.c
+++ b/libbb/u_signal_names.c
@@ -12,6 +12,18 @@
12//config: help 12//config: help
13//config: Support RTMIN[+n] and RTMAX[-n] signal names 13//config: Support RTMIN[+n] and RTMAX[-n] signal names
14//config: in kill, killall etc. This costs ~250 bytes. 14//config: in kill, killall etc. This costs ~250 bytes.
15//config:
16//config:config FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
17//config: bool "Use the definitions of SIGRTMIN/SIGRTMAX provided by libc"
18//config: default y
19//config: depends on FEATURE_RTMINMAX
20//config: help
21//config: Some C libraries reserve a few real-time signals for internal
22//config: use, and adjust the values of SIGRTMIN/SIGRTMAX seen by
23//config: applications accordingly. Saying yes here means that a signal
24//config: name RTMIN+n will be interpreted according to the libc definition
25//config: of SIGRTMIN, and not the raw definition provided by the kernel.
26//config: This behavior matches "kill -l RTMIN+n" from bash.
15 27
16#include "libbb.h" 28#include "libbb.h"
17 29
@@ -123,7 +135,7 @@ static const char signals[][7] ALIGN1 = {
123#ifdef SIGSYS 135#ifdef SIGSYS
124 [SIGSYS ] = "SYS", 136 [SIGSYS ] = "SYS",
125#endif 137#endif
126#if ENABLE_FEATURE_RTMINMAX 138#if ENABLE_FEATURE_RTMINMAX && !ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
127# ifdef __SIGRTMIN 139# ifdef __SIGRTMIN
128 [__SIGRTMIN] = "RTMIN", 140 [__SIGRTMIN] = "RTMIN",
129# endif 141# endif
@@ -168,36 +180,46 @@ int FAST_FUNC get_signum(const char *name)
168# endif 180# endif
169#endif 181#endif
170 182
171#if ENABLE_FEATURE_RTMINMAX 183#if ENABLE_FEATURE_RTMINMAX && defined(SIGRTMIN) && defined(SIGRTMAX)
172# if defined(SIGRTMIN) && defined(SIGRTMAX) 184 {
173/* libc may use some rt sigs for pthreads and therefore "remap" SIGRTMIN/MAX, 185# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
174 * but we want to use "raw" SIGRTMIN/MAX. Underscored names, if exist, provide 186 /* Use the libc provided values. */
175 * them. If they don't exist, fall back to non-underscored ones: */ 187 unsigned sigrtmin = SIGRTMIN;
188 unsigned sigrtmax = SIGRTMAX;
189# else
190 /* Use the "raw" SIGRTMIN/MAX. Underscored names, if exist, provide
191 * them. If they don't exist, fall back to non-underscored ones: */
176# if !defined(__SIGRTMIN) 192# if !defined(__SIGRTMIN)
177# define __SIGRTMIN SIGRTMIN 193# define __SIGRTMIN SIGRTMIN
178# endif 194# endif
179# if !defined(__SIGRTMAX) 195# if !defined(__SIGRTMAX)
180# define __SIGRTMAX SIGRTMAX 196# define __SIGRTMAX SIGRTMAX
181# endif 197# endif
182 if (strncasecmp(name, "RTMIN", 5) == 0) { 198
183 if (!name[5]) 199# define sigrtmin __SIGRTMIN
184 return __SIGRTMIN; 200# define sigrtmax __SIGRTMAX
185 if (name[5] == '+') { 201# endif
186 i = bb_strtou(name + 6, NULL, 10); 202 if (strncasecmp(name, "RTMIN", 5) == 0) {
187 if (!errno && i <= __SIGRTMAX - __SIGRTMIN) 203 if (!name[5])
188 return __SIGRTMIN + i; 204 return sigrtmin;
205 if (name[5] == '+') {
206 i = bb_strtou(name + 6, NULL, 10);
207 if (!errno && i <= sigrtmax - sigrtmin)
208 return sigrtmin + i;
209 }
189 } 210 }
190 } 211 else if (strncasecmp(name, "RTMAX", 5) == 0) {
191 else if (strncasecmp(name, "RTMAX", 5) == 0) { 212 if (!name[5])
192 if (!name[5]) 213 return sigrtmax;
193 return __SIGRTMAX; 214 if (name[5] == '-') {
194 if (name[5] == '-') { 215 i = bb_strtou(name + 6, NULL, 10);
195 i = bb_strtou(name + 6, NULL, 10); 216 if (!errno && i <= sigrtmax - sigrtmin)
196 if (!errno && i <= __SIGRTMAX - __SIGRTMIN) 217 return sigrtmax - i;
197 return __SIGRTMAX - i; 218 }
198 } 219 }
220# undef sigrtmin
221# undef sigrtmax
199 } 222 }
200# endif
201#endif 223#endif
202 224
203 return -1; 225 return -1;
@@ -228,8 +250,16 @@ void FAST_FUNC print_signames(void)
228 printf("%2u) %s\n", signo, name); 250 printf("%2u) %s\n", signo, name);
229 } 251 }
230#if ENABLE_FEATURE_RTMINMAX 252#if ENABLE_FEATURE_RTMINMAX
231# ifdef __SIGRTMAX 253# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
254# if defined(SIGRTMIN) && defined(SIGRTMAX)
255 printf("%2u) %s\n", SIGRTMIN, "RTMIN");
256 printf("%2u) %s\n", SIGRTMAX, "RTMAX");
257# endif
258# else
259// __SIGRTMIN is included in signals[] array.
260# ifdef __SIGRTMAX
232 printf("%2u) %s\n", __SIGRTMAX, "RTMAX"); 261 printf("%2u) %s\n", __SIGRTMAX, "RTMAX");
262# endif
233# endif 263# endif
234#endif 264#endif
235} 265}