[klibc] [klibc:update-dash] trap: Implement POSIX.1-2008 trap reset behaviour

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Thu Jan 24 19:15:42 PST 2019


Commit-ID:  ffba488a87578bfe0704dd906466fc64a88ff488
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=ffba488a87578bfe0704dd906466fc64a88ff488
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Mon, 6 Jun 2016 19:52:43 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000

[klibc] trap: Implement POSIX.1-2008 trap reset behaviour

Jonathan Perkin submitted a patch to fix the behaviour of trap
when the first argument is an integer.  Currently it is treated
as a command while POSIX requires it to be treated as a signal.

This patch is based on his idea but instead of adding an extra
argument to decode_signal I have added a new decode_signum helper.

Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/trap.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/usr/dash/trap.c b/usr/dash/trap.c
index a6997d4f..89ceff4f 100644
--- a/usr/dash/trap.c
+++ b/usr/dash/trap.c
@@ -78,6 +78,8 @@ volatile sig_atomic_t pendingsigs;
 /* received SIGCHLD */
 int gotsigchld;
 
+static int decode_signum(const char *);
+
 #ifdef mkinit
 INCLUDE "trap.h"
 INIT {
@@ -111,7 +113,7 @@ trapcmd(int argc, char **argv)
 		}
 		return 0;
 	}
-	if (!ap[1])
+	if (!ap[1] || decode_signum(*ap) >= 0)
 		action = NULL;
 	else
 		action = *ap++;
@@ -399,18 +401,27 @@ out:
 	/* NOTREACHED */
 }
 
-int decode_signal(const char *string, int minsig)
+static int decode_signum(const char *string)
 {
-	int signo;
+	int signo = -1;
 
 	if (is_number(string)) {
 		signo = atoi(string);
-		if (signo >= NSIG) {
-			return -1;
-		}
-		return signo;
+		if (signo >= NSIG)
+			signo = -1;
 	}
 
+	return signo;
+}
+
+int decode_signal(const char *string, int minsig)
+{
+	int signo;
+
+	signo = decode_signum(string);
+	if (signo >= 0)
+		return signo;
+
 	for (signo = minsig; signo < NSIG; signo++) {
 		if (sys_sigabbrev[signo] &&
 		    !strcasecmp(string, sys_sigabbrev[signo]))


More information about the klibc mailing list