From patchwork Mon Jun 6 11:52:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 9157943 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C2BBB60467 for ; Mon, 6 Jun 2016 11:53:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5069254F7 for ; Mon, 6 Jun 2016 11:53:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A84812780C; Mon, 6 Jun 2016 11:53:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B275254F7 for ; Mon, 6 Jun 2016 11:53:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751096AbcFFLw7 (ORCPT ); Mon, 6 Jun 2016 07:52:59 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:50840 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751039AbcFFLw7 (ORCPT ); Mon, 6 Jun 2016 07:52:59 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1b9t5P-0008Sn-Lf; Mon, 06 Jun 2016 21:52:51 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1b9t5J-0005kQ-T9; Mon, 06 Jun 2016 19:52:45 +0800 Date: Mon, 6 Jun 2016 19:52:43 +0800 From: Herbert Xu To: Jonathan Perkin Cc: dash@vger.kernel.org Subject: Re: trap: Implement POSIX.1-2008 trap reset behaviour (#2) Message-ID: <20160606115243.GA22071@gondor.apana.org.au> References: <20151207175047.GG735@joyent.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151207175047.GG735@joyent.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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;