Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Koichi Murase Newsgroups: gnu.bash.bug Subject: Re: [PATCH] Exit status by no-argument `return' for function calls in trap handlers Date: Sun, 19 Apr 2020 11:29:46 +0900 Lines: 117 Approved: bug-bash@gnu.org Message-ID: References: <7f1850ca-fb02-35db-e1f6-80d7ae937ff8@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="000000000000f3347c05a39b8e66" X-Trace: usenet.stanford.edu 1587263403 18540 209.51.188.17 (19 Apr 2020 02:30:03 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Chester Ramey Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K7iE0naxlhUdn8hnRCk7pVpeRBFqClK0h2FQNSk51+k=; b=jJgugLqIAQFl+TW6fjrWwQ9KHUNJT4Dl8k0sdBrf7IJxULws3qkFR2iqwtsXGQzZI6 4LZHSzTsaT/NnLDTnG5PNOsr1XNdV4YTRXUrEi30vrwIdWUVEVG8eHRC0/ne155W33Gd 1hPNMqLCPHIwEj0+vVpBTItruXlNj2o8V7bACh+Nqv3uekKH9VcFTWL1cfuDpI0pQuqs UZWQDo7hmxwa9faBKGEZ8MRDSCJ37JhlAlFapPuWqZBRv/Ztd8RlmWjOt9xVpwU5laPr t55FiW5PKP0wbIhGeDkUzbclZ6IvKZeJFgTqDUaWxBmfKckP+izHOkx+ZktHP2IYijNa ol/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K7iE0naxlhUdn8hnRCk7pVpeRBFqClK0h2FQNSk51+k=; b=E3I3fUoEgrdCb7vaigQfLXMZRLOf1F11wRrXMtO6pYYsZlT+61vNKn8cd3A0c9sTuA ukjZvfISaFWygR91AEphD3CdoDBPQ3qoVOQIs/UG6ffmbrHsLrOHQ/NT8w2IVklZ8cLl j1Z/GSuHziALkmEjDDHSv5rhc1eVoRE8Qb3bVoEJvPZ21Bm6Q1MDnLgpNbEW/Cbp415j lIa2ywCtyiKM+NYEZd1yCGmyG28FPkjh1z0SYFZs4BLUDtsYMf/f0OQytBJs5xFO6aBJ gFNQn7/PXW8OvHL9hF1s/pgICOofwrCTPE3Ur03qWdAfMhJAgR92LNjblTOY76k4m3vd i9fA== X-Gm-Message-State: AGi0Puakmq/M7XyjQq56Ai7JF+TGUQXahyeU20yOwyGxtNUo+h8YEPuu 3Am3Xa2l/VegZuoNAeEkkrgHMWVRU6x76b1Htow= X-Google-Smtp-Source: APiQypKvVFOgFJNZ04imESo+KLnhykorZw4DGr1onOJYa3DbCZUvYtFZa0Oxk0QUY6B7/0vkm7wMhHjnBRvTHI+TTaw= X-Received: by 2002:ac2:5185:: with SMTP id u5mr6452467lfi.64.1587263397078; Sat, 18 Apr 2020 19:29:57 -0700 (PDT) In-Reply-To: <7f1850ca-fb02-35db-e1f6-80d7ae937ff8@case.edu> Received-SPF: pass client-ip=2a00:1450:4864:20::141; envelope-from=myoga.murase@gmail.com; helo=mail-lf1-x141.google.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::141 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <7f1850ca-fb02-35db-e1f6-80d7ae937ff8@case.edu> Xref: csiph.com gnu.bash.bug:16171 --000000000000f3347c05a39b8e66 Content-Type: text/plain; charset="UTF-8" 2020-04-19 5:12 Chet Ramey : > 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. Thank you for the suggestion. Is the mailing list you mentioned above? I have created an account in opengroup.org and subscribed to the mailing list. I will later write a question on wording of `return' special builtin in that list. > That's an unreasonable statement, throwing out all uses of return without > an argument because of how it behaves while running a trap. OK. I agree that for the shell functions that will not be used in trap handlers, no-argument `return' can be used without problems. Actually the situation in my script (ble.sh) is a little bit special. In my script, some parts of Bash features are emulated. I run `eval -- "$PROMPT_COMMAND"' in SIGWINCH handler where `PROMPT_COMMAND' is specified by users so is not under the control of the script but under the control of the user. Naively, with interpretation (B), I need to put restrictions on the commands that can be specified in `PROMPT_COMMAND', on which there are no restrictions in the original Bash. The use of no-argument `return' is common, and such restrictions are non-trivial for users. In fact, there are already existing Bash configurations, that use no-argument `return' in `PROMPT_COMMAND', which I would like to support with my script. One example is `bash-preexec' (https://github.com/rcaloras/bash-preexec) which aims to provide a feature like `preexec' and `precmd' hooks of zsh. `bash-preexec' uses no-argument `return'. The configuration provided by iTerm2 for shell--terminal integration also uses this `bash-preexec' framework. I would appreciate it if you could provide me some suggestion on other ways to work around the general problems caused by such user-provided `PROMPT_COMMAND'? 2020-04-17 2:21 Koichi Murase : > Also, I have checked the behavior of other shells. `zsh', `ash' > family (dash/ash, busybox sh) and `posh' does not implement the > special treatment of `return' in trap handlers. `ksh' family > (ksh93, mksh) and `yash' implements the interpretation (B). There > is no existing implementation of (A). But currently I still think > the intepretation (A) is reasonable. If there is rationale for the > interpretation (B), I would like to know it. Let me correct this paragraph. Actually `zsh', `dash' and `busybox' implement the behavior of the interpretation (A). After my previous email, I noticed that there was an oversight in testing the shells. With the attached script `0015-test4.sh', $ bash 0015-test4.sh In trap-argument: last command preceding the trap action In a function call: last command preceding the trap action $ bash-4.3 0015-test4.sh In trap-argument: last command in the trap action In a function call: last command in the trap action $ zsh 0015-test4.sh In trap-argument: last command preceding the trap action In a function call: last command in the trap action $ dash 0015-test4.sh In trap-argument: last command preceding the trap action In a function call: last command in the trap action $ busybox sh 0015-test4.sh In trap-argument: last command preceding the trap action In a function call: last command in the trap action $ mksh 0015-test4.sh In trap-argument: last command preceding the trap action In a function call: last command preceding the trap action $ ksh 0015-test4.sh In trap-argument: last command preceding the trap action In a function call: last command preceding the trap action $ yash 0015-test4.sh In trap-argument: (failed to exit the function) In a function call: last command preceding the trap action $ posh 0015-test4.sh In trap-argument: last command in the trap action In a function call: last command in the trap action which can be summarized in the following list: Interpretation (A): zsh, dash, busybox Interpretation (B): bash-5.0, ksh, mksh Interpretation (B) [broken?]: yash Not implemented: bash-4.3, posh -- Koichi --000000000000f3347c05a39b8e66 Content-Type: text/x-sh; charset="US-ASCII"; name="0015-test4.sh" Content-Disposition: attachment; filename="0015-test4.sh" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_k96fjsqg0 IyEvYmluL2Jhc2gKCnNldGV4aXQoKSB7IHJldHVybiAiJDEiOyB9Cmludm9rZSgpIHsga2lsbCAt VVNSMSAkJDsgcmV0dXJuIDIyMjsgfQoKdHJhcCAnc2V0ZXhpdCAxMTE7IHJldHVybicgVVNSMQpp bnZva2UKY2FzZSAkPyBpbgooMCkgICBlY2hvICdJbiB0cmFwLWFyZ3VtZW50OiBsYXN0IGNvbW1h bmQgcHJlY2VkaW5nIHRoZSB0cmFwIGFjdGlvbicgOzsKKDExMSkgZWNobyAnSW4gdHJhcC1hcmd1 bWVudDogbGFzdCBjb21tYW5kIGluIHRoZSB0cmFwIGFjdGlvbicgOzsKKDIyMikgZWNobyAnSW4g dHJhcC1hcmd1bWVudDogKGZhaWxlZCB0byBleGl0IHRoZSBmdW5jdGlvbiknIDs7CigqKSAgIGVj aG8gJ0luIHRyYXAtYXJndW1lbnQ6ICh1bmV4cGVjdGVkKScgOzsKZXNhYwoKc3RhdD05OQpoYW5k bGVyKCkgeyBzZXRleGl0IDExMTsgcmV0dXJuOyB9CnRyYXAgJ2hhbmRsZXI7IHN0YXQ9JD87IHJl dHVybicgVVNSMQppbnZva2UKY2FzZSAkc3RhdCBpbgooMCkgICBlY2hvICdJbiBhIGZ1bmN0aW9u IGNhbGw6IGxhc3QgY29tbWFuZCBwcmVjZWRpbmcgdGhlIHRyYXAgYWN0aW9uJyA7OwooMTExKSBl Y2hvICdJbiBhIGZ1bmN0aW9uIGNhbGw6IGxhc3QgY29tbWFuZCBpbiB0aGUgdHJhcCBhY3Rpb24n IDs7CigqKSAgIGVjaG8gJ0luIGEgZnVuY3Rpb24gY2FsbDogKHVuZXhwZWN0ZWQpJyA7Owplc2Fj Cg== --000000000000f3347c05a39b8e66--