Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Harald van Dijk Newsgroups: gnu.bash.bug Subject: Re: Bizarre interaction bug involving bash w/ lastpipe + Almquist 'wait' Date: Thu, 6 Feb 2020 19:29:41 +0000 Lines: 51 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: quoted-printable X-Trace: usenet.stanford.edu 1581022061 13456 209.51.188.17 (6 Feb 2020 20:47:41 GMT) X-Complaints-To: action@cs.stanford.edu To: Martijn Dekker , DASH shell mailing list , busybox , Bug reports for the GNU Bourne Again SHell , Robert Elz , Jilles Tjoelker Envelope-to: bug-bash@gnu.org DKIM-Filter: OpenDKIM Filter v2.11.0 mail.gigawatt.nl D983EC80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gigawatt.nl; s=default; t=1581017472; bh=z0AsFWtGv5aHhM+JXjEm9LmaIwdhOACmPWL9qX1xpH8=; l=1586; h=Subject:To:References:From:Date:In-Reply-To:From; b=Y36IJAZGHeE69UQSGceOCXuN6IA+z7uk1avkKVbQw5c9jv8PTqlR9MH3MUAVHyq85 6C7ZcvFVgCVjY53z34m1bi6etpDVBkGEBiW0tKq716wYvEJlBNMlXCqAwcg9CeNf4P GW/bviBHGwMuh1nsqdLxNYssLUczEruDzX2PbyWE= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Thunderbird/73.0 In-Reply-To: <10e3756b-5e8f-ba00-df0d-b36c93fa2281@inlv.org> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:41d0:801:2000::19e9 X-Mailman-Approved-At: Thu, 06 Feb 2020 15:47:39 -0500 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: <10e3756b-5e8f-ba00-df0d-b36c93fa2281@inlv.org> Xref: csiph.com gnu.bash.bug:15869 On 06/02/2020 16:12, Martijn Dekker wrote: > This is probably the strangest bug (or maybe pair of bugs) I've run int= o=20 > in nearly five years of breaking shells by developing modernish. >=20 > I've traced it to an interaction between bash >=3D 4.2 (i.e.: bash with= =20 > shopt -s lastpipe) and variants of the Almquist shell, at least: dash,=20 > gwsh, Busybox ash, FreeBSD sh, and NetBSD 9.0rc2 sh. >=20 > Symptom: if 'return' is invoked on bash in the last element of a pipe=20 > executed in the main shell environment, then if you subsequently 'exec'= =20 > an Almquist shell variant so that it has the same PID, its 'wait'=20 > builtin breaks. >=20 > I can consistently reproduce this on Linux, macOS, FreeBSD, NetBSD=20 > 9.0rc2, OpenBSD, and Solaris. >=20 > To reproduce this, you need bash >=3D 4.2, some Almquist shell variant,= =20 > and these two test scripts: >=20 > ---begin test.bash--- > fn() { > =C2=A0=C2=A0=C2=A0=C2=A0: | return > } > shopt -s lastpipe || exit > fn > exec "${1:-dash}" test.ash > ---end test.bash--- >=20 > ---begin test.ash--- > echo '*ash-begin' > : & > echo '*ash-middle' > wait "$!" > echo '*ash-end' > ---end test.ash--- >=20 > When executing test.bash with dash, gwsh, Busybox ash, or FreeBSD sh,=20 > then test.ash simply waits forever on executing 'wait "$!"'. Nice test. bash leaves the process in a state where SIGCHLD is blocked,=20 and the various ash-based shells do not unblock it. Because of that,=20 they do not pick up on the fact that the child process has terminated. I=20 would consider this a bug both in bash and in the ash-based shells. Cheers, Harald van Dijk