Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Martijn Dekker Newsgroups: gnu.bash.bug Subject: Bizarre interaction bug involving bash w/ lastpipe + Almquist 'wait' Date: Thu, 6 Feb 2020 16:12:06 +0000 Lines: 69 Approved: bug-bash@gnu.org Message-ID: References: <10e3756b-5e8f-ba00-df0d-b36c93fa2281@inlv.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1581005551 4820 209.51.188.17 (6 Feb 2020 16:12:31 GMT) X-Complaints-To: action@cs.stanford.edu To: DASH shell mailing list , busybox , Bug reports for the GNU Bourne Again SHell , Robert Elz , Jilles Tjoelker , Harald van Dijk Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 37.59.109.123 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: <10e3756b-5e8f-ba00-df0d-b36c93fa2281@inlv.org> Xref: csiph.com gnu.bash.bug:15868 This is probably the strangest bug (or maybe pair of bugs) I've run into in nearly five years of breaking shells by developing modernish. I've traced it to an interaction between bash >= 4.2 (i.e.: bash with shopt -s lastpipe) and variants of the Almquist shell, at least: dash, gwsh, Busybox ash, FreeBSD sh, and NetBSD 9.0rc2 sh. Symptom: if 'return' is invoked on bash in the last element of a pipe executed in the main shell environment, then if you subsequently 'exec' an Almquist shell variant so that it has the same PID, its 'wait' builtin breaks. I can consistently reproduce this on Linux, macOS, FreeBSD, NetBSD 9.0rc2, OpenBSD, and Solaris. To reproduce this, you need bash >= 4.2, some Almquist shell variant, and these two test scripts: ---begin test.bash--- fn() { : | return } shopt -s lastpipe || exit fn exec "${1:-dash}" test.ash ---end test.bash--- ---begin test.ash--- echo '*ash-begin' : & echo '*ash-middle' wait "$!" echo '*ash-end' ---end test.ash--- When executing test.bash with dash, gwsh, Busybox ash, or FreeBSD sh, then test.ash simply waits forever on executing 'wait "$!"'. $ bash test.bash *ash-begin *ash-middle (nothing until ^C) NetBSD sh behaves differently. NetBSD 8.1 sh (as installed on sdf.org and sdf-eu.org) seem to act completely normally, but NetBSD 9.0rc2 sh (on my VirtualBox test VM) segfaults. Output on NetBSD 9.0rc2: $ bash test.bash /bin/sh *ash-begin *ash-middle [1] Segmentation fault bash test.bash sh I don't know if the different NetBSD sh behaviour is because the older NetBSD sh doesn't have the bug, or because some factor on the sdf*.org systems causes it to not be triggered. To me, this smells like the use of some uninitialised value on various Almquist shells. Tracing that is beyond my expertise though. Whether this also represents a bug in bash or not, I can't say. But no other shells trigger this that I've found, not even ksh93 and zsh which also execute the last element of a pipe in the main shell environment. - Martijn -- modernish -- harness the shell https://github.com/modernish/modernish