From: Herbert Xu <herbert@gondor.apana.org.au>
To: Jonathan Perkin <jperkin@joyent.com>
Cc: dash@vger.kernel.org
Subject: Re: trap: Implement POSIX.1-2008 trap reset behaviour (#2)
Date: Mon, 6 Jun 2016 19:52:43 +0800 [thread overview]
Message-ID: <20160606115243.GA22071@gondor.apana.org.au> (raw)
In-Reply-To: <20151207175047.GG735@joyent.com>
On Mon, Dec 07, 2015 at 05:50:47PM +0000, Jonathan Perkin wrote:
> Clarifies a couple of issues with the previous patch, and expands on
> the rationale in the commit message. Sorry for the noise -- jperkin
Thanks for the patch.
I've decided to do something similar to your final patch:
---8<---
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>
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;
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2016-06-06 11:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-07 17:50 [PATCH] trap: Implement POSIX.1-2008 trap reset behaviour (#2) Jonathan Perkin
2015-12-08 8:24 ` Herbert Xu
2015-12-08 9:51 ` Jonathan Perkin
2016-06-06 11:52 ` Herbert Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160606115243.GA22071@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
--cc=jperkin@joyent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).