bug-bash
[Top][All Lists]
Advanced

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

[PATCH] decode_signal: allow all sane forms of SIGRTMIN+n


From: Rasmus Villemoes
Subject: [PATCH] decode_signal: allow all sane forms of SIGRTMIN+n
Date: Wed, 12 Sep 2018 12:11:24 +0200

I have a program I'd like to send SIGRTMIN+20, because that's the
spelling used in its documentation. Currently, bash only accepts the
symbolic names in the signal_names array, meaning I'd have to spell it
SIGRTMAX-10 on linux.

One workaround is of course to use

  kill -n $(($(kill -l SIGRTMIN) + 20)) pid

but it's more user-friendly to allow the form

  kill -s SIGRTMIN+20 pid

For symmetry, also accept SIGRTMAX-n expressions.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
 trap.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/trap.c b/trap.c
index eb8ecf3a..dd80c220 100644
--- a/trap.c
+++ b/trap.c
@@ -242,6 +242,21 @@ decode_signal (string, flags)
   if (legal_number (string, &sig))
     return ((sig >= 0 && sig < NSIG) ? (int)sig : NO_SIG);
 
+#if defined(SIGRTMIN) && defined(SIGRTMAX)
+  if (STREQN (string, "SIGRTMIN+", 9)) {
+    if (legal_number (string + 9, &sig) && sig >= 0 && sig <= SIGRTMAX - 
SIGRTMIN)
+      return SIGRTMIN + sig;
+    else
+      return NO_SIG;
+  }
+  if (STREQN (string, "SIGRTMAX-", 9)) {
+    if (legal_number (string + 9, &sig) && sig >= 0 && sig <= SIGRTMAX - 
SIGRTMIN)
+      return SIGRTMAX - sig;
+    else
+      return NO_SIG;
+  }
+#endif
+
   /* A leading `SIG' may be omitted. */
   for (sig = 0; sig < BASH_NSIG; sig++)
     {
-- 
2.16.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]