From patchwork Sat May 5 16:02:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10382199 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5653760353 for ; Sat, 5 May 2018 16:02:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E766223A4 for ; Sat, 5 May 2018 16:02:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 910AE29087; Sat, 5 May 2018 16:02:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD57029056 for ; Sat, 5 May 2018 16:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751211AbeEEQCq (ORCPT ); Sat, 5 May 2018 12:02:46 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:35738 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751206AbeEEQCq (ORCPT ); Sat, 5 May 2018 12:02:46 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fEze0-0007Pk-Lp; Sun, 06 May 2018 00:02:44 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fEzdz-00064H-8r; Sun, 06 May 2018 00:02:43 +0800 Date: Sun, 6 May 2018 00:02:43 +0800 From: Herbert Xu To: Leah Neukirchen Cc: dash@vger.kernel.org Subject: Re: Regression in dash 0.5.10 related to subshells Message-ID: <20180505160243.t5rujv3eifiust5a@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87wowjsfcw.fsf@gmail.com> X-Newsgroups: apana.lists.os.linux.dash Organization: Core User-Agent: NeoMutt/20170113 (1.7.2) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Leah Neukirchen wrote: > Hi, > > as of dash 0.5.10, this script waits for the sleep to terminate before > executing the last line, which no other /bin/sh does. > dash 0.5.9.1 worked fine. > > > #!/bin/sh > sleep 3 & > echo first in main shell > ( echo in subshell; ) > echo back to main shell > > > Found by users of the Void Linux project: > https://github.com/voidlinux/void-packages/issues/14123 Thanks for the report! This patch should fix the problem: ---8<--- Subject: jobs - Do not block when waiting on SIGCHLD Because of the nature of SIGCHLD, the process may have already been waited on and therefore we must be prepared for the case that wait may block. So ensure that it doesn't by using WNOHANG. Fixes: 03876c0743a5 ("eval: Reap zombies after built-in...") Signed-off-by: Herbert Xu diff --git a/src/jobs.c b/src/jobs.c index 1a97c54..6dc555f 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -975,8 +975,8 @@ waitforjob(struct job *jp) int st; TRACE(("waitforjob(%%%d) called\n", jp ? jobno(jp) : 0)); - while ((jp && jp->state == JOBRUNNING) || gotsigchld) - dowait(DOWAIT_BLOCK, jp); + while (jp ? jp->state == JOBRUNNING : gotsigchld) + dowait(jp ? DOWAIT_BLOCK : DOWAIT_NORMAL, jp); if (!jp) return exitstatus; st = getstatus(jp);