From patchwork Mon Dec 7 17:50:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Perkin X-Patchwork-Id: 7788571 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-dash@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E35D4BEEE1 for ; Mon, 7 Dec 2015 17:50:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 183B0203E3 for ; Mon, 7 Dec 2015 17:50:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 024F9203B7 for ; Mon, 7 Dec 2015 17:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932380AbbLGRux (ORCPT ); Mon, 7 Dec 2015 12:50:53 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:34497 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932376AbbLGRuw (ORCPT ); Mon, 7 Dec 2015 12:50:52 -0500 Received: by wmvv187 with SMTP id v187so178439186wmv.1 for ; Mon, 07 Dec 2015 09:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joyent.com; s=google; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=QLvXHCsUZC/Ymh/Rg+H+ZMFb0wpyC2++kj1aN3juuGg=; b=kKEsKDvdTXdjlM5yICcCAHwtXSS79k0eEI58+6GxFQSGNrmJu+tm8EEmYuxrZT5zP5 S0pxocg2uwF5fPQs3Cq41AJEOALiv1d84XPfmoAjM7mIaYMQUf0wVl86cdFPO9VF/9zq 5g2cQrCZyRaFdXKbYmKLdm7BIGEOj0wkeu9N0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=QLvXHCsUZC/Ymh/Rg+H+ZMFb0wpyC2++kj1aN3juuGg=; b=F7Qy2abCInf7q1bL9rZ2PQgkcN6pywbitzrWfEdh7PjbFD9pTMplQvL8cpRwkLMqgx p9IcOc2jGVpi9PYx2zcadQ1aW3JiFYfOa3h3c+oPf4nxvhPPFT7GRwHSN/khvZqh/z++ KfVRS10XPZCnMp/2PHCjBezA37vR1uFtgQf/GlRoneMAYy5dAnAAneq6vmIJ8DNHtHHE 1dcEk52QNVOH7qpPkTGp1+yTyqXgXoM9GZng2x0vcP0jr+tGB/fuDRRiFqRlwPih3i3M 0E8AHokygnY7r5WKetDQMWtHq1VsXJ4Up55yRrfTVFbKE2geKhQjjBag5HJTaOAYiqpy oLjg== X-Gm-Message-State: ALoCoQlGZQPZG/q4cUGlK1sXYbPDZZFuQm0Bme7wBAcLwd3+5w9ku5APaX5rVdgsJqDra1T96irD X-Received: by 10.195.11.233 with SMTP id el9mr34049113wjd.145.1449510651382; Mon, 07 Dec 2015 09:50:51 -0800 (PST) Received: from joyent.com (host86-144-234-20.range86-144.btcentralplus.com. [86.144.234.20]) by smtp.gmail.com with ESMTPSA id lx4sm26276349wjb.5.2015.12.07.09.50.50 for (version=TLSv1/SSLv3 cipher=OTHER); Mon, 07 Dec 2015 09:50:50 -0800 (PST) Date: Mon, 7 Dec 2015 17:50:47 +0000 From: Jonathan Perkin To: dash@vger.kernel.org Subject: [PATCH] trap: Implement POSIX.1-2008 trap reset behaviour (#2) Message-ID: <20151207175047.GG735@joyent.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Clarifies a couple of issues with the previous patch, and expands on the rationale in the commit message. Sorry for the noise -- jperkin POSIX.1-2008 for trap adds the following behaviour: If the first operand is an unsigned decimal integer, the shell shall treat all operands as conditions, and shall reset each condition to the default value. The interpretation of this behaviour differs among other shells. In the case where the first operand is an invalid signo: bash-4.3.39(1), zsh-5.1.1: $ trap echo 1 2 3 $ trap 100 1 2 $ trap trap -- '100' SIGHUP trap -- '100' SIGINT trap -- 'echo' SIGQUIT mksh-51: $ trap echo 1 2 3 $ trap 100 1 2 mksh: trap: bad signal '100' $ trap trap -- echo QUIT ksh 93u+: $ trap echo 1 2 3 $ trap 100 1 2 ksh: trap: 100: bad trap $ trap trap -- echo QUIT trap -- echo INT trap -- echo HUP As the standard does not appear to specify that the first operand must be a valid signo for this behaviour to be triggered, we align with the ksh behaviour: $ trap echo 1 2 3 $ trap 100 1 2 trap: 100: bad trap $ trap trap -- 'echo' HUP trap -- 'echo' INT trap -- 'echo' QUIT As for the case of the first operand being a signal name: bash-4.3.39(1), mksh-51, ksh 93u+: $ trap echo 1 2 3 $ trap HUP 2 $ trap trap -- 'echo' SIGHUP trap -- 'HUP' SIGINT trap -- 'echo' SIGQUIT zsh-5.1.1: $ trap echo 1 2 3 $ trap HUP 2 $ trap trap -- echo QUIT Here we go with the majority and a strict interpretation of the standard, parsing it as a string rather than a signal: $ trap echo 1 2 3 $ trap HUP 2 $ trap trap -- 'echo' HUP trap -- 'HUP' INT trap -- 'echo' QUIT --- src/trap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trap.c b/src/trap.c index 82d4263..3dc1949 100644 --- a/src/trap.c +++ b/src/trap.c @@ -112,7 +112,7 @@ trapcmd(int argc, char **argv) } return 0; } - if (!ap[1]) + if ((!ap[1]) || (is_number(*ap))) action = NULL; else action = *ap++;