Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16167

Re: [PATCH] Exit status by no-argument `return' for function calls in trap handlers

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: [PATCH] Exit status by no-argument `return' for function calls in trap handlers
Date Sat, 18 Apr 2020 16:12:01 -0400
Organization ITS, Case Western Reserve University
Lines 48
Approved bug-bash@gnu.org
Message-ID <mailman.623.1587240727.3066.bug-bash@gnu.org> (permalink)
References <CAFLRLk_+Je7ZHEYp_a4PLBwYFZffqfsYgp5jtPCnAH=apmHatQ@mail.gmail.com> <7f1850ca-fb02-35db-e1f6-80d7ae937ff8@case.edu>
Reply-To chet.ramey@case.edu
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1587240728 5701 209.51.188.17 (18 Apr 2020 20:12:08 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet.ramey@case.edu
To Koichi Murase <myoga.murase@gmail.com>, bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1587240725; bh=t/AF6OXLxWqiY9w/XkxEet7DvVWigoF0sfJSC0ybHtI=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=etFpkxz2TlDIpvzsKRiwaYZaIsJY9jwuONpE3sfWo03H8SAflHjlBkDGq58mMTnqBQ 6ackA1l9AoBeSZy8VJsLjN8+XcNN6bIUQH8E9uDpm62wG9H9rxTBr955QaQzRhrPUQg MQj+dm5nvCL8YVi51RVZeuAMiM/Us5xUee98Utg7fqgEoo5tZxmu6nT14OmLIsIHaK0 YoDeqnwmQUOwmwH8MQWD6YpVnw+cbMyimHbMaPOo2dSHevb8ysT3YDemhvFEBTE9I3A jhnYj9kyvAN+RX/vqv+Rm9laiiB0vEQzbQS7zD3edKCXygmqkbNxfjHbGAGnn3t2o2T mvPHoAiw==
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1587240723; bh=jBQUsXbsoIxZq3uK2NtewCpfk3mkjX/49QDnze1nQCI=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=sW6So5HwraTEsj5rnSjYPENBbij6n0SjzEafEgZEE2BvxzY0aEs/C2lywXfIZztUBs jt/Rcvist78h4Tv+DeO+uceI9L7gt29YjORe6BtNXNk3V0WoZ5ZzzOJ5RQfCm3u8nOn VJx/RdjYo7VPUcM/pWzu8PjEYaLX2EBaRNEBbIqmMxjIHTjy82DXMBGuYImdfsAJr9U a/wgrcdAhv7YOPrJ0qfaohdxhCimziIo1xFamL7w6R/hI0xjjgCbXzFWtFEUHFvSoKo 3sGz6e9p13aAJ/kdmsMzMxrnb+89VEW2kfuSDueV8NDewnJdb2FzLgqh75V9pqDiUHl K97cfB+A==
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=g-case; h=reply-to:cc:subject:to:references:from:autocrypt:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=jBQUsXbsoIxZq3uK2NtewCpfk3mkjX/49QDnze1nQCI=; b=XMEhqXYipYKLziMl5r74S3Y49ZRIso2wwRlKhBHt4ZViZa4Hb+2ODeBsZ8Yunl5vBL 7orImW7MSouKTo/bNJ8kW1n4V1veaV2IW7EuzYYBF6gZe5ZvIxIS75l4tAU6eTHlB2es Xk6hF1+WCVuhSoPlD6yEuxqWe1tWkah/mSf82LZ0Em6ByEUv1F2TXNFRmzKl+vWH5pKV 6kB538iZlo429scV/wVn56a9IGa0NJnHcwsMbyIK6+aChU5q4zml2G1NicI3phn7Bzx1 UXOFSPw/5r9I4bc/vSnAxnCZzrUibCw3/XPVBTAcn6OeOaG2eUBQxoHmODEFXJi4+P6X NjgA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:cc:subject:to:references:from:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=jBQUsXbsoIxZq3uK2NtewCpfk3mkjX/49QDnze1nQCI=; b=Y9IDi0e9v1botSQZAp5z6xr8bm091uoL0hj/oTx88cRSkPruMIvVathxZFl/q/TZ6Z CdTfVynPpQ2xPTGuidBd9Thjaluwkywka+JGSuz5+vSA8OpdC3FYooLHOYVr67XWKWIV brdbLOEDuLBqVcCh/jN7L6JmM2oYxYk0vyaH5wBvcVl5DfEec7SqA8+eZJLRwQ1zT0+s 9N3hhUYib3KkNfyCm+qg5nywEfEEZVrzfCbQ59O8tuwSosTeIJ9V+Ud3XJyn4RdMGh40 IEMQyExTA1bbJpv+rssr4V72NO4uuKW1d5d7dVizT82HbdKg9arWFywRWnrHmHGfqYlo 8+hQ==
X-Gm-Message-State AGi0PuZKUwvSz/npa1OmGmk29aC7wqldCRfRwhq9dKPWgPhfN7Oo4R99 ifRRYNRDCdImec3hLLHoyDIaC/9juRZH+0x7wT13ilGdL47HzI7Ka2m9xsThN/zweix3CnE33Ky Krldmpbh6Qnw=
X-Received by 2002:a0c:ba20:: with SMTP id w32mr8261720qvf.3.1587240722999; Sat, 18 Apr 2020 13:12:02 -0700 (PDT)
X-Google-Smtp-Source APiQypIsA5GeWD8qkGW1IjwjCoT5s6oPXDkRhe4UILVZfB67QVdML4rZCvp9Poxy1nkBMl/C1gL85A==
X-Received by 2002:a0c:ba20:: with SMTP id w32mr8261696qvf.3.1587240722689; Sat, 18 Apr 2020 13:12:02 -0700 (PDT)
Autocrypt addr=chet.ramey@case.edu; prefer-encrypt=mutual; keydata= mQGiBEEOsGwRBACFa0A1oa71HSZLWxAx0svXz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+aJG+0KZiEkEGBECAAkFAkEOsG8CGwwACgkQu1hp 8GTqdKvjcACfZlkVCDwaz/NTO9cy3t69oWpVPNwAnRwe0qk/WL/gfhH346xh5B3HFbFN
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.7.0
In-Reply-To <CAFLRLk_+Je7ZHEYp_a4PLBwYFZffqfsYgp5jtPCnAH=apmHatQ@mail.gmail.com>
Content-Language en-US
X-Mirapoint-IP-Reputation reputation=Good-1, source=Queried, refid=tid=0001.0A020303.5E9B52DD.0005, actions=tag
X-Mirapoint-IP-Reputation reputation=good-1, source=Fixed, refid=n/a, actions=tag
X-Junkmail-Status score=7/80, host=mpv1-2015.case.edu
X-Junkmail-PrAS-Raw score=7/80, refid=2.7.2:2020.4.18.192717:17:7.944, ip=, rules=__YOUTUBE_RCVD, DKIM_SIGNATURE, __X_GOOGLE_DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __SUBJ_REPLY, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __SUBJ_ALPHA_END, __TO_MALFORMED_2, __MULTIPLE_RCPTS_TO_X2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC1, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_ENDS_IN_SLASH, __URI_NO_WWW, __CP_URI_IN_BODY, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __MAIL_CHAIN, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138
Received-SPF pass client-ip=129.22.103.226; envelope-from=chet.ramey@case.edu; helo=mpv1-2015.case.edu
X-detected-operating-system by eggs.gnu.org: Linux 2.4.x-2.6.x [generic] [fuzzy]
X-Received-From 129.22.103.226
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <7f1850ca-fb02-35db-e1f6-80d7ae937ff8@case.edu>
X-Mailman-Original-References <CAFLRLk_+Je7ZHEYp_a4PLBwYFZffqfsYgp5jtPCnAH=apmHatQ@mail.gmail.com>
Xref csiph.com gnu.bash.bug:16167

Show key headers only | View raw


On 4/16/20 1:21 PM, Koichi Murase wrote:

> Bash Version: 5.0
> Patch Level: 11
> Release Status: release
> 
> Summary:
> 
>   The behavior of no-argument `return' in trap handlers has been
>   changed from Bash 4.4 to follow the description of POSIX.  Recently
>   this behavior caused problems in my Bash script.  I am wondering
>   whether this change actually matches with the behavior meant by
>   POSIX because the change introduces unreasonable constraints in
>   writing shell functions.
> 
>   For the condition of this special treatment of `return', POSIX says
>   ``When return is executed in a trap action''.  Here are two possible
>   interpretation: (A) `return's specified in the argument string of
>   `trap' builtin are affected, or (B) all the `return's in entire
>   runtime function-call tree in trap processing are affected.  I guess
>   that POSIX wanted to provide a way to exit functions that received
>   signals without changing the value of `$?'.  If that is the case,
>   the POSIX should have meant (A).  However, the current Bash
>   implementation behaves as if it follows the interpretation (B).

The POSIX wording seems straightforward and implies (B). The `action'
is a string that is defined to behave as if it were the argument to
`eval', so it can be an arbitrary command, which makes (A) unlikely.

You could always ask the austin-group list for an interpretation, or
send me something that I could forward to the list for you.


>   If all the `return's in the entire function-call tree are affected
>   in trap processing as in the interpretation (B), one cannot reliably
>   use no-argument `return' to return the last-command exit status.  To
>   avoid the problem, one has to always write the exit status
>   explicitly as `return $?', and there is no use case for no-argument
>   `return' at all. 

That's an unreasonable statement, throwing out all uses of return without
an argument because of how it behaves while running a trap.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: [PATCH] Exit status by no-argument `return' for function calls in trap handlers Chet Ramey <chet.ramey@case.edu> - 2020-04-18 16:12 -0400

csiph-web