Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen When not compiling -DSMALL permit use of names ...



details:   https://anonhg.NetBSD.org/src/rev/1847c17db9a9
branches:  trunk
changeset: 937531:1847c17db9a9
user:      kre <kre%NetBSD.org@localhost>
date:      Thu Aug 20 22:56:56 2020 +0000

description:
When not compiling -DSMALL permit use of names RTMIN[+n] and RTMAX[-n]
(where n is a decimal integer in the range [0 .. SIGRTMAX-SIGRTMIN].
As usual a leading "sig" is ignored and the strings are case independent.

Some implementations do not name the real time signals, and using
labels like RTMIN+3 can be the only way they can be manipulated,
so allow that technique (we still return the RTnn names on the inverse
translation though).

Because this is used by both kill(1) and sh(1) the kill and trap
commands both gain access to the new notation (when !SMALL).

diffstat:

 lib/libc/gen/signalname.3   |  16 ++++++++++++++--
 lib/libc/gen/signalnumber.c |  39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 3 deletions(-)

diffs (104 lines):

diff -r 4307b676da7f -r 1847c17db9a9 lib/libc/gen/signalname.3
--- a/lib/libc/gen/signalname.3 Thu Aug 20 22:20:50 2020 +0000
+++ b/lib/libc/gen/signalname.3 Thu Aug 20 22:56:56 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: signalname.3,v 1.2 2017/05/14 12:35:46 wiz Exp $
+.\" $NetBSD: signalname.3,v 1.3 2020/08/20 22:56:56 kre Exp $
 .\"
 .\" Available to all and sundry, without restriction on use, or other
 .\" limitations, and without fee.   Also without any warranty of fitness
@@ -76,6 +76,17 @@
 .Fa name
 is ignored.
 .Pp
+This implementation also accepts
+.Dv rtmax Ns \&[\-n]
+and
+.Dv rtmin Ns \&[+n]
+.Po
+where the optional
+.Ar n
+is a decimal integer between 0 and SIGRTMAX\-SIGRTMIN
+.Pc
+to refer to the real time signals.
+.Pp
 The
 .Fn signalnumber
 function returns the signal number,
@@ -93,7 +104,8 @@
 .Pp
 The
 .Fn signalnext
-function returns minus one (\-1) on error, if the given signal
+function returns minus one (\-1) on error,
+that is, if the given signal
 .Fa sig
 is neither a valid signal number nor zero.
 It returns zero when the input signal number,
diff -r 4307b676da7f -r 1847c17db9a9 lib/libc/gen/signalnumber.c
--- a/lib/libc/gen/signalnumber.c       Thu Aug 20 22:20:50 2020 +0000
+++ b/lib/libc/gen/signalnumber.c       Thu Aug 20 22:56:56 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signalnumber.c,v 1.2 2018/01/04 20:57:29 kamil Exp $ */
+/* $NetBSD: signalnumber.c,v 1.3 2020/08/20 22:56:56 kre Exp $ */
 
 /*
  * Software available to all and sundry without limitations
@@ -20,7 +20,9 @@
 #include "namespace.h"
 
 #include <signal.h>
+#include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 /*
  * signalnumber()
@@ -42,6 +44,10 @@
 signalnumber(const char *name)
 {
        int i;
+#ifndef SMALL
+       long offs;
+       char *ep;
+#endif
 
        if (strncasecmp(name, "sig", 3) == 0)
                name += 3;
@@ -50,5 +56,36 @@
                if (sys_signame[i] != NULL &&
                    strcasecmp(name, sys_signame[i]) == 0)
                        return i;
+
+#ifndef SMALL
+       if (strncasecmp(name, "rtm", 3) == 0) {
+               name += 3;
+               if (strncasecmp(name, "ax", 2) == 0)
+                       i = SIGRTMAX;
+               else if (strncasecmp(name, "in", 2) == 0)
+                       i = SIGRTMIN;
+               else
+                       return 0;
+               name += 2;
+               if (name[0] == '\0')
+                       return i;
+               if (i == SIGRTMAX && name[0] != '-')
+                       return 0;
+               if (i == SIGRTMIN && name[0] != '+')
+                       return 0;
+               if (!isdigit((unsigned char)name[1]))
+                       return 0;
+               offs = strtol(name+1, &ep, 10);
+               if (ep == name+1 || *ep != '\0' ||
+                   offs < 0 || offs > SIGRTMAX-SIGRTMIN)
+                       return 0;
+               if (name[0] == '+')
+                       i += (int)offs;
+               else
+                       i -= (int)offs;
+               if (i >= SIGRTMIN && i <= SIGRTMAX)
+                       return i;
+       }
+#endif
        return 0;
 }



Home | Main Index | Thread Index | Old Index