summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-06-06 19:52:43 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2016-09-02 22:10:56 +0800
commit551215bb2f05b6ed0a639e1a20b88906ddd7ef9b (patch)
treefe196361b9b00c679d6c652a18d29f47eaf0f65c /src
parenteval: Fix exit status when calling eval/dot with no commands (diff)
downloaddash-551215bb2f05b6ed0a639e1a20b88906ddd7ef9b.tar.gz
dash-551215bb2f05b6ed0a639e1a20b88906ddd7ef9b.zip
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@gondor.apana.org.au>
Diffstat (limited to 'src')
-rw-r--r--src/trap.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/trap.c b/src/trap.c
index 82d4263..edb9938 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -79,6 +79,8 @@ int gotsigchld;
 
 extern char *signal_names[];
 
+static int decode_signum(const char *);
+
 #ifdef mkinit
 INCLUDE "trap.h"
 INIT {
@@ -112,7 +114,7 @@ trapcmd(int argc, char **argv)
 		}
 		return 0;
 	}
-	if (!ap[1])
+	if (!ap[1] || decode_signum(*ap) >= 0)
 		action = NULL;
 	else
 		action = *ap++;
@@ -400,18 +402,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 (!strcasecmp(string, signal_names[signo])) {
 			return signo;