From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43446-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.1 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id c72c1063 for ; Tue, 11 Sep 2018 15:32:28 +0000 (UTC) Received: (qmail 14297 invoked by alias); 11 Sep 2018 15:32:16 -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: 43446 Received: (qmail 25786 invoked by uid 1010); 11 Sep 2018 15:32:16 -0000 X-Qmail-Scanner-Diagnostics: from mailout1.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.11):SA:0(-6.9/5.0):. Processed in 1.370205 secs); 11 Sep 2018 15:32:16 -0000 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180911153211euoutp01a5b3e49e4f4f3296eeba015c68d6917e~TYkGVVC2V0155601556euoutp01a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1536679931; bh=U+7mII5mFVvkB4f3wKjTGp59jd1tYG6Mi4hsKaHjKV8=; h=Date:From:To:Subject:In-Reply-To:References:From; b=pQXOD6ZrqW0cApI7OKea+tyISSzPs+hShwNSr/4KfiXWMEGXhv7ARPl9PLzjfKIln xXKezZdG+K84+BFedkFRP7ZxhgeyAMVLEuaHp1/SC4awI3mV2wOA7hpI4kVpTwzr2w USpmAcASyhWHzZ7lBEwYEijCzQkWWrSvyOVhrxIA= X-AuditID: cbfec7f4-835ff700000010c6-18-5b97dffab190 Date: Tue, 11 Sep 2018 16:32:08 +0100 From: Peter Stephenson To: Subject: Re: PATCH: Rimmerworld pipeline race In-Reply-To: <20180911160326.33dfd575@camnpupstephen.cam.scsc.local> Organization: SCSC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDIsWRmVeSWpSXmKPExsWy7djP87q/7k+PNmhZYmhxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mh7e+cFacN+4YuXiSYwNjLvUuxg5OSQETCROHN3F1sXIxSEk sIJRYtvnXmYIp49JYuKOR0wQTi+TxNpDe5lgWnru7WYDsYUEljNKPNwQCWEDFU3dLgXRcIZR 4unXHSwQzgVGic+bV4B1sAioSjw5MJMVxGYTMJSYumk2I4gtIiApca35NJgtLKArsfLnOyCb g4NTwEViyaUUEJNfQEjiQrMtxA32Ekf3nAS7h1dAUOLkzCcsIDazgLzE9rdzmCFqPrNJ/Plr DFFTJnG2eyEjRNxFYsbpfjYIW1ji1fEt7BC2jMT/nfPBHpYQaGeUWDPpNTuE08MosenoHahu a4m+2xfBbmMW0JRYv0sfIuwosX3HNWaQsIQAn8SNt4IQ9/BJTNo2HSrMK9HRJgRRrSaxo2kr 4wRG5VlIPpiF5INZCPMXMDKvYhRPLS3OTU8tNspLLdcrTswtLs1L10vOz93ECEwDp/8d/7KD cdefpEOMAhyMSjy8K/ZNjxZiTSwrrsw9xCjBwawkwrtLZ1q0EG9KYmVValF+fFFpTmrxIUZp DhYlcV4+rbRoIYH0xJLU7NTUgtQimCwTB6dUA+O8P/nufyMldPYo+23Y97WjTjMygmEtv8yf NV2z7itvXuvyepo+F/+F7bx8Ufummqh0KL4PKiuZ6M7cx3zY9ehtLd2bovPzYwWvflhgY5jP dm7SJDWzJHam35KXLWvncelutos6mbHxtrZFY4HKTPejqTfnZQh+tdVcqRNowvB4horFOh31 FUosxRmJhlrMRcWJAJk99FL/AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeLIzCtJLcpLzFFi42I5/e/4Xd2f96dHG/xpN7M42PyQyYHRY9XB D0wBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GQ/v/GAtuG9csXLxJMYGxl3qXYycHBICJhI993azdTFycQgJLGWUuLzvIBNEQkbi05WP7BC2 sMSfa11QRd1MEs0dXxghnDOMEhMfvWOCcC4wSiz69oUZpIVFQFXiyYGZrCA2m4ChxNRNsxlB bBEBSYlrzafBbGEBXYmVP9+B2bwCzhIbXx4D6uXg4BRwkVhyKQVi5nR2ibebTjGCxPkFhCQu NNtCXGQvcXTPSSaIVkGJkzOfsIDYzAI6EidWHWOGsOUltr+dwzyBUXgWkrJZSMpmISlbwMi8 ilEktbQ4Nz232EivODG3uDQvXS85P3cTIzAqth37uWUHY9e74EOMAhyMSjy8K/ZNjxZiTSwr rsw9xCjBwawkwrtLZ1q0EG9KYmVValF+fFFpTmrxIUZTYFhMZJYSTc4HRmxeSbyhqaG5haWh ubG5sZmFkjjveYPKKCGB9MSS1OzU1ILUIpg+Jg5OqQZGhyxjOaFnyYJ+Z2vUVRo+6v5cyxXi dGGe9lmJ2bcszi1fFsxsopz0ape/RVR56GfVR0zWNxWfPmXe6R/Ke6PLfEqvWOTimu7n0bcf 5wj2MnpNi1Q9s+i0c+GEN+v+bbmS9TUrwKg3+J293I7Zn1buv8T5b9OCixtuTDjy+cvKG9IV x7fJvp0opcRSnJFoqMVcVJwIANW/o2KgAgAA Message-Id: <20180911153210eucas1p29b83cf55a4c598f615663227f2acf6c2~TYkFBW5Yh1169611696eucas1p2N@eucas1p2.samsung.com> X-CMS-MailID: 20180911153210eucas1p29b83cf55a4c598f615663227f2acf6c2 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180911144121epcas3p414601927147a878c2e59bbf9c7f1da24 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180911144121epcas3p414601927147a878c2e59bbf9c7f1da24 References: <20180905210740.5a6aec15@pws-HP.localdomain> <20180906090902.1f344e9f@camnpupstephen.cam.scsc.local> <20180906092250eucas1p13d651e07ae627d179dd0701e65f912d6~RxTLztJrP2263722637eucas1p12@eucas1p1.samsung.com> <20180907101852.62415ff9@camnpupstephen.cam.scsc.local> <20180907122145.2af5bcba@camnpupstephen.cam.scsc.local> <20180907150140.46a05880@camnpupstephen.cam.scsc.local> <20180907145828eucas1p2755db3a0eb9725cb3a29121033e77f21~SJhg-Al9h2728227282eucas1p2z@eucas1p2.samsung.com> <20180910225530.GI4613@sym.noone.org> <20180911085827eucas1p1edf8e50634f8d977941f7b80f43ce025~TTMUOH4zU2107621076eucas1p1p@eucas1p1.samsung.com> <20180911144045.GA21032@cventin.lip.ens-lyon.fr> <20180911160326.33dfd575@camnpupstephen.cam.scsc.local> On Tue, 11 Sep 2018 16:03:26 +0100 Peter Stephenson wrote: > On Tue, 11 Sep 2018 16:40:46 +0200 > Vincent Lefevre wrote: > > Apparently, it is not entirely fixed, or perhaps this is another > > problem: > > > > cventin% for i in 1 2 3; do : | { : | tput init } done > > zsh: suspended (tty output) for i in 1 2 3; do; : | { : | tput init; }; done > > You can get it with any outer current-shell construct. > > { : | { : | more } } > > Looks a bit different to me. Not happening in the instrumented build > on the job_control_debug branch, either, so even harder to debug. OK, suppose we also pass back information about list_pipe_job itself, not just the group leader? This seems to work for me. I'm in two minds whether to pass the whole structure into addproc(): it seems to be abusing the interface. pws diff --git a/Src/exec.c b/Src/exec.c index 074265f..b9af9ea 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1002,7 +1002,7 @@ enum { /**/ static void -entersubsh(int flags, int *gleaderp) +entersubsh(int flags, struct entersubsh_ret *retp) { int i, sig, monitor, job_control_ok; @@ -1036,8 +1036,10 @@ entersubsh(int flags, int *gleaderp) if (!(flags & ESUB_ASYNC)) attachtty(jobtab[thisjob].gleader); } - if (gleaderp) - *gleaderp = jobtab[list_pipe_job].gleader; + if (retp) { + retp->gleader = jobtab[list_pipe_job].gleader; + retp->list_pipe_job = list_pipe_job; + } } else if (!jobtab[thisjob].gleader || setpgrp(0L, jobtab[thisjob].gleader) == -1) { @@ -1058,8 +1060,11 @@ entersubsh(int flags, int *gleaderp) setpgrp(0L, jobtab[thisjob].gleader); if (!(flags & ESUB_ASYNC)) attachtty(jobtab[thisjob].gleader); - if (gleaderp) - *gleaderp = jobtab[thisjob].gleader; + if (retp) { + retp->gleader = jobtab[thisjob].gleader; + if (list_pipe_job != thisjob) + retp->list_pipe_job = list_pipe_job; + } } } if (!(flags & ESUB_FAKE)) @@ -1692,7 +1697,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) curjob = newjob; DPUTS(!list_pipe_pid, "invalid list_pipe_pid"); addproc(list_pipe_pid, list_pipe_text, 0, - &list_pipe_start, -1); + &list_pipe_start, -1, -1); /* If the super-job contains only the sub-shell, the sub-shell is the group leader. */ @@ -2185,7 +2190,7 @@ closemn(struct multio **mfds, int fd, int type) } mn->ct = 1; mn->fds[0] = fd; - addproc(pid, NULL, 1, &bgtime, -1); + addproc(pid, NULL, 1, &bgtime, -1, -1); child_unblock(); return; } @@ -2686,10 +2691,12 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc, { pid_t pid; int synch[2], flags; - int gleader = -1; + struct entersubsh_ret esret; struct timeval bgtime; child_block(); + esret.gleader = -1; + esret.list_pipe_job = -1; if (pipe(synch) < 0) { zerr("pipe failed: %e", errno); @@ -2703,7 +2710,7 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc, } if (pid) { close(synch[1]); - read_loop(synch[0], (char *)&gleader, sizeof(gleader)); + read_loop(synch[0], (char *)&esret, sizeof(esret)); close(synch[0]); if (how & Z_ASYNC) { lastpid = (zlong) pid; @@ -2721,7 +2728,7 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc, 3 : WC_ASSIGN_NUM(ac) + 2); } } - addproc(pid, text, 0, &bgtime, gleader); + addproc(pid, text, 0, &bgtime, esret.gleader, esret.list_pipe_job); if (oautocont >= 0) opts[AUTOCONTINUE] = oautocont; pipecleanfilelist(jobtab[thisjob].filelist, 1); @@ -2736,8 +2743,8 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc, if (type == WC_SUBSH && !(how & Z_ASYNC)) flags |= ESUB_JOB_CONTROL; *filelistp = jobtab[thisjob].filelist; - entersubsh(flags, &gleader); - write(synch[1], &gleader, sizeof(gleader)); + entersubsh(flags, &esret); + write(synch[1], &esret, sizeof(esret)); close(synch[1]); zclose(close_if_forked); @@ -4876,7 +4883,7 @@ getproc(char *cmd, char **eptr) if (pid == -1) return NULL; if (!out) - addproc(pid, NULL, 1, &bgtime, -1); + addproc(pid, NULL, 1, &bgtime, -1, -1); procsubstpid = pid; return pnam; } @@ -4913,7 +4920,7 @@ getproc(char *cmd, char **eptr) addfilelist(NULL, fd); if (!out) { - addproc(pid, NULL, 1, &bgtime, -1); + addproc(pid, NULL, 1, &bgtime, -1, -1); } procsubstpid = pid; return pnam; @@ -4965,7 +4972,7 @@ getpipe(char *cmd, int nullexec) return -1; } if (!nullexec) - addproc(pid, NULL, 1, &bgtime, -1); + addproc(pid, NULL, 1, &bgtime, -1, -1); procsubstpid = pid; return pipes[!out]; } diff --git a/Src/jobs.c b/Src/jobs.c index ba87a17..db2e87e 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1375,7 +1375,8 @@ deletejob(Job jn, int disowning) /**/ void -addproc(pid_t pid, char *text, int aux, struct timeval *bgtime, int gleader) +addproc(pid_t pid, char *text, int aux, struct timeval *bgtime, + int gleader, int list_pipe_job_used) { Process pn, *pnlist; @@ -1397,10 +1398,15 @@ addproc(pid_t pid, char *text, int aux, struct timeval *bgtime, int gleader) * the job, then it's the group leader. * * Exception: if the forked subshell reported its own group - * leader, set that. + * leader, set that. If it reported the use of list_pipe_job, + * set it for that, too. */ - if (!jobtab[thisjob].gleader) - jobtab[thisjob].gleader = (gleader != -1) ? gleader : pid; + if (gleader != -1) { + jobtab[thisjob].gleader = gleader; + if (list_pipe_job_used != -1) + jobtab[list_pipe_job_used].gleader = gleader; + } else if (!jobtab[thisjob].gleader) + jobtab[thisjob].gleader = pid; /* attach this process to end of process list of current job */ pnlist = &jobtab[thisjob].procs; } diff --git a/Src/zsh.h b/Src/zsh.h index 8e7f20b..b81db15 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -505,6 +505,14 @@ enum { ZCONTEXT_PARSE = (1<<2) }; +/* Report from entersubsh() to pass subshell info to addproc */ +struct entersubsh_ret { + /* Process group leader chosen by subshell, else -1 */ + int gleader; + /* list_pipe_job setting used by subshell, else -1 */ + int list_pipe_job; +}; + /**************************/ /* Abstract types for zsh */ /**************************/