Skip to content
Snippets Groups Projects
Commit 551215bb authored by Herbert Xu's avatar Herbert Xu
Browse files

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: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 17a5f24e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -79,6 +79,8 @@ int gotsigchld;
 
extern char *signal_names[];
 
static int decode_signum(const char *);
#ifdef mkinit
INCLUDE "trap.h"
INIT {
Loading
Loading
@@ -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++;
Loading
Loading
@@ -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;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment