mirror of https://github.com/mirror/busybox.git
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
7b276fc175
. 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>
1_30_stable
parent
93ef5dd640
commit
571e525a14
|
@ -12,6 +12,18 @@
|
||||||
//config: help
|
//config: help
|
||||||
//config: Support RTMIN[+n] and RTMAX[-n] signal names
|
//config: Support RTMIN[+n] and RTMAX[-n] signal names
|
||||||
//config: in kill, killall etc. This costs ~250 bytes.
|
//config: in kill, killall etc. This costs ~250 bytes.
|
||||||
|
//config:
|
||||||
|
//config:config FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
|
||||||
|
//config: bool "Use the definitions of SIGRTMIN/SIGRTMAX provided by libc"
|
||||||
|
//config: default y
|
||||||
|
//config: depends on FEATURE_RTMINMAX
|
||||||
|
//config: help
|
||||||
|
//config: Some C libraries reserve a few real-time signals for internal
|
||||||
|
//config: use, and adjust the values of SIGRTMIN/SIGRTMAX seen by
|
||||||
|
//config: applications accordingly. Saying yes here means that a signal
|
||||||
|
//config: name RTMIN+n will be interpreted according to the libc definition
|
||||||
|
//config: of SIGRTMIN, and not the raw definition provided by the kernel.
|
||||||
|
//config: This behavior matches "kill -l RTMIN+n" from bash.
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
@ -123,7 +135,7 @@ static const char signals[][7] ALIGN1 = {
|
||||||
#ifdef SIGSYS
|
#ifdef SIGSYS
|
||||||
[SIGSYS ] = "SYS",
|
[SIGSYS ] = "SYS",
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_RTMINMAX
|
#if ENABLE_FEATURE_RTMINMAX && !ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
|
||||||
# ifdef __SIGRTMIN
|
# ifdef __SIGRTMIN
|
||||||
[__SIGRTMIN] = "RTMIN",
|
[__SIGRTMIN] = "RTMIN",
|
||||||
# endif
|
# endif
|
||||||
|
@ -168,36 +180,46 @@ int FAST_FUNC get_signum(const char *name)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_FEATURE_RTMINMAX
|
#if ENABLE_FEATURE_RTMINMAX && defined(SIGRTMIN) && defined(SIGRTMAX)
|
||||||
# if defined(SIGRTMIN) && defined(SIGRTMAX)
|
{
|
||||||
/* libc may use some rt sigs for pthreads and therefore "remap" SIGRTMIN/MAX,
|
# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
|
||||||
* but we want to use "raw" SIGRTMIN/MAX. Underscored names, if exist, provide
|
/* Use the libc provided values. */
|
||||||
|
unsigned sigrtmin = SIGRTMIN;
|
||||||
|
unsigned sigrtmax = SIGRTMAX;
|
||||||
|
# else
|
||||||
|
/* Use the "raw" SIGRTMIN/MAX. Underscored names, if exist, provide
|
||||||
* them. If they don't exist, fall back to non-underscored ones: */
|
* them. If they don't exist, fall back to non-underscored ones: */
|
||||||
# if !defined(__SIGRTMIN)
|
# if !defined(__SIGRTMIN)
|
||||||
# define __SIGRTMIN SIGRTMIN
|
# define __SIGRTMIN SIGRTMIN
|
||||||
# endif
|
# endif
|
||||||
# if !defined(__SIGRTMAX)
|
# if !defined(__SIGRTMAX)
|
||||||
# define __SIGRTMAX SIGRTMAX
|
# define __SIGRTMAX SIGRTMAX
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define sigrtmin __SIGRTMIN
|
||||||
|
# define sigrtmax __SIGRTMAX
|
||||||
# endif
|
# endif
|
||||||
if (strncasecmp(name, "RTMIN", 5) == 0) {
|
if (strncasecmp(name, "RTMIN", 5) == 0) {
|
||||||
if (!name[5])
|
if (!name[5])
|
||||||
return __SIGRTMIN;
|
return sigrtmin;
|
||||||
if (name[5] == '+') {
|
if (name[5] == '+') {
|
||||||
i = bb_strtou(name + 6, NULL, 10);
|
i = bb_strtou(name + 6, NULL, 10);
|
||||||
if (!errno && i <= __SIGRTMAX - __SIGRTMIN)
|
if (!errno && i <= sigrtmax - sigrtmin)
|
||||||
return __SIGRTMIN + i;
|
return sigrtmin + i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncasecmp(name, "RTMAX", 5) == 0) {
|
else if (strncasecmp(name, "RTMAX", 5) == 0) {
|
||||||
if (!name[5])
|
if (!name[5])
|
||||||
return __SIGRTMAX;
|
return sigrtmax;
|
||||||
if (name[5] == '-') {
|
if (name[5] == '-') {
|
||||||
i = bb_strtou(name + 6, NULL, 10);
|
i = bb_strtou(name + 6, NULL, 10);
|
||||||
if (!errno && i <= __SIGRTMAX - __SIGRTMIN)
|
if (!errno && i <= sigrtmax - sigrtmin)
|
||||||
return __SIGRTMAX - i;
|
return sigrtmax - i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
# undef sigrtmin
|
||||||
|
# undef sigrtmax
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -228,8 +250,16 @@ void FAST_FUNC print_signames(void)
|
||||||
printf("%2u) %s\n", signo, name);
|
printf("%2u) %s\n", signo, name);
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_RTMINMAX
|
#if ENABLE_FEATURE_RTMINMAX
|
||||||
|
# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
|
||||||
|
# if defined(SIGRTMIN) && defined(SIGRTMAX)
|
||||||
|
printf("%2u) %s\n", SIGRTMIN, "RTMIN");
|
||||||
|
printf("%2u) %s\n", SIGRTMAX, "RTMAX");
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
// __SIGRTMIN is included in signals[] array.
|
||||||
# ifdef __SIGRTMAX
|
# ifdef __SIGRTMAX
|
||||||
printf("%2u) %s\n", __SIGRTMAX, "RTMAX");
|
printf("%2u) %s\n", __SIGRTMAX, "RTMAX");
|
||||||
# endif
|
# endif
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue