aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-06-06 19:52:43 +0800
committerBen Hutchings <ben@decadent.org.uk>2020-03-28 21:42:54 +0000
commitb9c84707e06be25579b9402f740c763ed79cbdde (patch)
tree62fe1aaacefc2cafeffacf1309126e2a5316effc
parent54653f129781515d3eaff2aa26078ef376bc5a6f (diff)
downloadklibc-b9c84707e06be25579b9402f740c763ed79cbdde.tar.gz
[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@gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/dash/trap.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/usr/dash/trap.c b/usr/dash/trap.c
index a6997d4f0204e..89ceff4fe7c1a 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]))