From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9281 invoked by alias); 12 Apr 2018 16:30:15 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42630 Received: (qmail 9822 invoked by uid 1010); 12 Apr 2018 16:30:14 -0000 X-Qmail-Scanner-Diagnostics: from mailout2.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.12):SA:0(-1.9/5.0):. Processed in 15.236691 secs); 12 Apr 2018 16:30:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_DKIMWL_WL_HIGH,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180412162345euoutp026ae643b6279fd36af2ca9e1645f74894~kvNuvdOUY2646626466euoutp02X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1523550225; bh=yJ7PP0SG4beLwAKFVh06dfpf84w4HNWaB7aZ7FAQ+Ic=; h=Date:From:To:Subject:In-reply-to:References:From; b=SBCofJMp65n6rawH4Gq1jb2/gnrYwe+QBiIxCi+rM8bJB8V0HXTCcWQFuVt9VJyL+ edBMs1c2yirqCLwUYjFih8D3fQrQUBbGHlPlJlzPE4fSWwHZj1YS6896HDzpHucVpD +irs9vVyKl0AKXY90A9CwGOGBmN6C+pmcGgVKBaA= X-AuditID: cbfec7f2-1dbff70000011644-55-5acf881060ce Date: Thu, 12 Apr 2018 17:23:42 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups Message-id: <20180412172342.52df6b10@camnpupstephen.cam.scsc.local> In-reply-to: <180411151025.ZM19332@torch.brasslantern.com> Organization: SCSC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEIsWRmVeSWpSXmKPExsWy7djPc7oCHeejDCb+1LI42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGXtPHWYrmCJRcWJtL2MD4w3BLkYODgkBE4m9T/K7GLk4hARW MEosvNDKAuH0Mkn0H5zPDlN075w/RHwZo8STrlOMEM40JokT02ewQjhnGCV+/pnCBOFcYJR4 +nklI0g7i4CqxOyniV2MnBxsAoYSUzfNZgSxRQS0JHacPMkEYgsLJEic3bMDzOYVcJa4ubYT rJVTwEqiaYcaiMkvICRxodkWpEJCwF7i6J6TUNWCEj8m32MBsZkFdCS2bXvMDmHLS2xe85YZ 5BoJgQlsEv1/NjBDNLtIzJ13lw3CFpZ4dXwLO4QtI3F5cjcLREMzo8Ta+/ehinoYJWYtDoWw rSX6bl9khNjAJzFp23RmSAjxSnS0CUGUeEhcu/QZaqajxKq9bdDwecEssX/qGaYJjPKzkBw+ C8nhs5AcvoCReRWjeGppcW56arFhXmq5XnFibnFpXrpecn7uJkZgzJ/+d/zTDsavl5IOMQpw MCrx8FZUn48SYk0sK67MPcQowcGsJMJb2wAU4k1JrKxKLcqPLyrNSS0+xCjNwaIkzhunURcl JJCeWJKanZpakFoEk2Xi4JRqYGyoYnjqYr58dtp87dxT/O51OcqbDDTObtN88kLpjb80m+TR ie8i6/T5XsWfv/GiKTq0/tgp/uPyr73+HZqRl8QoaxrbtzCj4PKzRQL586Q7jjT0VH2OlX/f KzLFs2N9bqfGebE1hf6PzT8rJitPsp8RZ9nHuSX4SgpTcPoDd+1LWlVzL3O8UGIpzkg01GIu Kk4EAPIQ9wz1AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPLMWRmVeSWpSXmKPExsVy+t/xa7oCHeejDN52ClgcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujL2nDrMVTJGoOLG2l7GB8YZgFyMHh4SAicS9c/5djFwcQgJL GCUuz77E0sXICeTMYJJYuMgbwj7HKPF1fQZE0QVGifZPfcwgzSwCqhKznyaC1LAJGEpM3TSb EcQWEdCS2HHyJBOILSyQILHoyQSwOK+As8TNtZ2MIK2cAlYSTTvUIEa+YJbYfryFHSTOLyAk caHZFqRcQsBe4ugeiDG8AoISPybfAzuNGWj85m1NrBC2vMTmNW+ZIc5Ul7hxdzf7BEahWUha ZiFpmYWkZQEj8ypGkdTS4tz03GIjveLE3OLSvHS95PzcTYzAYN127OeWHYxd74IPMQpwMCrx 8FZUn48SYk0sK67MPcQowcGsJMJb2wAU4k1JrKxKLcqPLyrNSS0+xCjNwaIkznveoDJKSCA9 sSQ1OzW1ILUIJsvEwSnVwMhTsV/jy5IFBxrsrwVGpD7867+rsTvyrKjnVxahKctttux7+mJC fE8iS+dib/8bch0pZ7szjBZfeHz7V4STVaROZvPTX9s2tzbXSZa9XarpsvnW0UshjzbmF03Q lnqwNL1psuGzqmI71fJ5524Wry92jHFUmJ5xPzik+XZQU29Yh0pL2BVdcyWW4oxEQy3mouJE ABLQAchSAgAA X-CMS-MailID: 20180412162344eucas1p242aaedc3cf3eed7af7691223f04542fa X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180324221021epcas1p184507a6328dbd505b97db69c1f9d8194 X-RootMTR: 20180324221021epcas1p184507a6328dbd505b97db69c1f9d8194 References: <20180323161612.GB4857@chaz.gmail.com> <180323163614.ZM10192@torch.brasslantern.com> <180323221959.ZM27569@torch.brasslantern.com> <20180324080514.txxyrb3qiztu4pqt@gmail.com> <180324150945.ZM32251@torch.brasslantern.com> <20180410124545.13fccd5d@camnpupstephen.cam.scsc.local> <20180410145926.64c4f671@camnpupstephen.cam.scsc.local> <180411151025.ZM19332@torch.brasslantern.com> On Wed, 11 Apr 2018 15:10:24 -0700 Bart Schaefer wrote: > On Apr 10, 2:59pm, Peter Stephenson wrote: > } Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components > in diff } > } + if (pn->pid == jn->gleader) { > } + jn->gleader = 0; > } + /* HERE: check this was actually in > foreground... */ } + attachtty(mypgrp); > } + } > > I think attachtty() will simply fail here if mypgrp is not already in > the foreground, but I confess not to be 100% certain. The man page suggests it's SIGTTOU time, though this isn't my natural territory either. I think the right test is for STAT_NOSTTY, which is the flag associated with running in the background. (Paranoid checK: we set this with "bg" as well as "&".) Moving the unqueuing inside readoutput() both catches other similar cases and allows us to continue protecting memory allocation while allowing signals around the blocking read. So I think this is a definite improvement, though it's probably not safe enough to sneak into 5.5.1. pws diff --git a/Src/exec.c b/Src/exec.c index e154d12..65ce348 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4576,10 +4576,20 @@ readoutput(int in, int qt, int *readerror) char *buf, *ptr; int bsiz, c, cnt = 0; FILE *fin; + int q = queue_signal_level(); fin = fdopen(in, "r"); ret = newlinklist(); ptr = buf = (char *) hcalloc(bsiz = 64); + /* + * We need to be sensitive to SIGCHLD else we can be + * stuck forever with important processes unreaped. + * The case that triggered this was where the exiting + * process is group leader of the foreground process and we need + * to reclaim the terminal else ^C doesn't work. + */ + dont_queue_signals(); + child_unblock(); while ((c = fgetc(fin)) != EOF || errno == EINTR) { if (c == EOF) { errno = 0; @@ -4592,13 +4602,18 @@ readoutput(int in, int qt, int *readerror) cnt++; } if (++cnt >= bsiz) { - char *pp = (char *) hcalloc(bsiz *= 2); + char *pp; + queue_signals(); + pp = (char *) hcalloc(bsiz *= 2); + dont_queue_signals(); memcpy(pp, buf, cnt - 1); ptr = (buf = pp) + cnt - 1; } *ptr++ = c; } + child_block(); + restore_queue_signals(q); if (readerror) *readerror = ferror(fin) ? errno : 0; fclose(fin); diff --git a/Src/signals.c b/Src/signals.c index 94f379e..2a6aa3f 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -537,6 +537,19 @@ wait_for_processes(void) #else update_process(pn, status); #endif + if (pn->pid == jn->gleader) { + jn->gleader = 0; + if (!(jn->stat & STAT_NOSTTY)) { + /* + * This PID was in control of the terminal; + * reclaim terminal now it has exited. + * It's still possible some future forked + * process of this job will become group + * leader, however. + */ + attachtty(mypgrp); + } + } } update_job(jn); } else if (findproc(pid, &jn, &pn, 1)) {