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

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:48:48 PDT 2020


Commit-ID:  b9c84707e06be25579b9402f740c763ed79cbdde
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=b9c84707e06be25579b9402f740c763ed79cbdde
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: Sat, 28 Mar 2020 21:42:54 +0000

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

[ dash commit 551215bb2f05b6ed0a639e1a20b88906ddd7ef9b ]

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