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:

# kill -l RTMIN+2
36
# busybox kill -l RTMIN+2
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 <[email protected]>
---
 libbb/u_signal_names.c | 49 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c
index b3038e32d..5ef5c3f28 100644
--- a/libbb/u_signal_names.c
+++ b/libbb/u_signal_names.c
@@ -12,6 +12,15 @@
 //config:      help
 //config:      Support RTMIN[+n] and RTMAX[-n] signal names
 //config:      in kill, killall etc. This costs ~250 bytes.
+//config:config FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
+//config:      bool "Use the definitions of SIGRTMIN/SIGRTMAX provided by libc"
+//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.
 
 #include "libbb.h"
 
@@ -123,7 +132,7 @@ static const char signals[][7] ALIGN1 = {
 #ifdef SIGSYS
        [SIGSYS   ] = "SYS",
 #endif
-#if ENABLE_FEATURE_RTMINMAX
+#if ENABLE_FEATURE_RTMINMAX && !ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
 # ifdef __SIGRTMIN
        [__SIGRTMIN] = "RTMIN",
 # endif
@@ -140,6 +149,7 @@ static const char signals[][7] ALIGN1 = {
 int FAST_FUNC get_signum(const char *name)
 {
        unsigned i;
+       unsigned sigrtmin, sigrtmax;
 
        i = bb_strtou(name, NULL, 10);
        if (!errno && i < NSIG) /* for shells, we allow 0 too */
@@ -168,10 +178,13 @@ int FAST_FUNC get_signum(const char *name)
 # endif
 #endif
 
-#if ENABLE_FEATURE_RTMINMAX
-# if defined(SIGRTMIN) && defined(SIGRTMAX)
-/* libc may use some rt sigs for pthreads and therefore "remap" SIGRTMIN/MAX,
- * but we want to use "raw" SIGRTMIN/MAX. Underscored names, if exist, provide
+#if ENABLE_FEATURE_RTMINMAX && defined(SIGRTMIN) && defined(SIGRTMAX)
+# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
+/* Use the libc provided values. */
+       sigrtmin = SIGRTMIN;
+       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: */
 #  if !defined(__SIGRTMIN)
 #   define __SIGRTMIN SIGRTMIN
@@ -179,25 +192,27 @@ int FAST_FUNC get_signum(const char *name)
 #  if !defined(__SIGRTMAX)
 #   define __SIGRTMAX SIGRTMAX
 #  endif
+       sigrtmin = __SIGRTMIN;
+       sigrtmax = __SIGRTMAX;
+# endif
        if (strncasecmp(name, "RTMIN", 5) == 0) {
                if (!name[5])
-                       return __SIGRTMIN;
+                       return sigrtmin;
                if (name[5] == '+') {
                        i = bb_strtou(name + 6, NULL, 10);
-                       if (!errno && i <= __SIGRTMAX - __SIGRTMIN)
-                               return __SIGRTMIN + i;
+                       if (!errno && i <= sigrtmax - sigrtmin)
+                               return sigrtmin + i;
                }
        }
        else if (strncasecmp(name, "RTMAX", 5) == 0) {
                if (!name[5])
-                       return __SIGRTMAX;
+                       return sigrtmax;
                if (name[5] == '-') {
                        i = bb_strtou(name + 6, NULL, 10);
-                       if (!errno && i <= __SIGRTMAX - __SIGRTMIN)
-                               return __SIGRTMAX - i;
+                       if (!errno && i <= sigrtmax - sigrtmin)
+                               return sigrtmax - i;
                }
        }
-# endif
 #endif
 
        return -1;
@@ -228,8 +243,16 @@ void FAST_FUNC print_signames(void)
                        printf("%2u) %s\n", signo, name);
        }
 #if ENABLE_FEATURE_RTMINMAX
-# ifdef __SIGRTMAX
+# 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
        printf("%2u) %s\n", __SIGRTMAX, "RTMAX");
+#  endif
 # endif
 #endif
 }
-- 
2.16.4

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to