From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6330 invoked by alias); 3 Jul 2017 15:09:47 -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: X-Seq: 41391 Received: (qmail 19874 invoked from network); 3 Jul 2017 15:09:47 -0000 X-Qmail-Scanner-Diagnostics: from mailout4.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.14):SA:0(-5.0/5.0):. Processed in 2.239302 secs); 03 Jul 2017 15:09:47 -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=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.samsung.com designates 210.118.77.14 as permitted sender) X-AuditID: cbfec7f4-f79806d000001279-16-595a5e316e25 Date: Mon, 03 Jul 2017 16:09:33 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: interrupt handling bug (again?) Message-id: <20170703160933.633e5e52@pwslap01u.europe.root.pri> In-reply-to: <170624120310.ZM30935@torch.brasslantern.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDIsWRmVeSWpSXmKPExsWy7djP87qGcVGRBl+nG1scbH7I5MDoserg B6YAxigum5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WAVWJN03/GUFsNgFDiambZgPZ HBwiAtoS7R/FQMLCAjoSp3uugJXzCthL7HtwGaycU8BK4sOK04wQM68xSpx81g9WxC+gL3H1 7ycmiPvsJWZeOcMI0Swo8WPyPbC7mQW0JDZva2KFsOUlNq95ywxiCwmoS9y4u5t9AqPwLCQt s5C0zELSsoCReRWjSGppcW56brGRXnFibnFpXrpecn7uJkZgHG079nPLDsaud8GHGAU4GJV4 eDWcoiKFWBPLiitzDzFKcDArifBuiwEK8aYkVlalFuXHF5XmpBYfYjQFBsxEZinR5HxgjOeV xBuaGJpbGhoZW1iYGxkpifNO/XAlXEggPbEkNTs1tSC1CKaPiYNTqoEx5WyQHffs94YXBCoe r50ta2qZPK+WqZz9K5/Ysn1aZrP+Ztd779me+l33QkKtQviRww2yDUUKrn96Xnya0my3dt7R xRNuaqTO+St8eOPmE0+CdDd2n2J+s3zjio7lqqqsNR9VNLrvCKssbLNOU3p/wvWy384J8cra PcbbZzevlfBcb/TZMX6NEktxRqKhFnNRcSIAVqwyX7kCAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170703150937eucas1p2882fec34ef9b090be46a61c67c7a9c16 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170624190325epcas3p2a13b51de05278521139c6cbcf39ff776 X-RootMTR: 20170624190325epcas3p2a13b51de05278521139c6cbcf39ff776 References: <170624120310.ZM30935@torch.brasslantern.com> Backgrounded shell code with subproceses: On Sat, 24 Jun 2017 12:03:10 -0700 Bart Schaefer wrote: > If you > instead disown before the foreground job is done, the job table entry > for the foreground job is deleted, so the parent never notices that > it has exited and never resumes the loop at all. I agree with this. However, I think we can do slightly better by delaying the disown to the point where we send SIGCONT to the superjob (the background copy of the shell process) after finding it has no associated processes in the current shell. At that point it will start its own processes, so we never need to interact with it again. This seems to work, and I've documented the effect. Is it weird enough that we should print a warning from "disown", or is that just going to cause more confusion than it removes (warnings of a technical nature often do, in my experience)? I reckon simply pointing people at the documentation if they ask is probably good enough. BTW, I think I don't need to check if there are actually processes associated with the superjob, since if there aren't (in which case it's marked was WASSUPER instead of SUPERJOB) disowning immediately has no bad effects. pws diff --git a/Doc/Zsh/jobs.yo b/Doc/Zsh/jobs.yo index 6262dd2..44e0a44 100644 --- a/Doc/Zsh/jobs.yo +++ b/Doc/Zsh/jobs.yo @@ -49,6 +49,12 @@ in the parent shell. Thus the behaviour is different from the case where the function was never suspended. Zsh is different from many other shells in this regard. +One additional side effect is that use of tt(disown) with a job +created by suspending shell code in this fashion is delayed: the +job can only be disowned once any process started from the parent +shell has terminated. At that point, the job disappears silently +from the process list. + The same behaviour is found when the shell is executing code as the right hand side of a pipeline or any complex shell construct such as tt(if), tt(for), etc., in order that the entire block of code diff --git a/Src/jobs.c b/Src/jobs.c index 32f7daa..66dfb5a 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -277,6 +277,10 @@ handle_sub(int job, int fg) (!jn->procs->next || cp || jn->procs->pid != jn->gleader)) attachtty(jn->gleader); kill(sj->other, SIGCONT); + if (jn->stat & STAT_DISOWN) + { + deletejob(jn, 1); + } } curjob = jn - jobtab; } else if (sj->stat & STAT_STOPPED) { @@ -2375,6 +2379,10 @@ bin_fg(char *name, char **argv, Options ops, int func) printjob(job + (oldjobtab ? oldjobtab : jobtab), lng, 2); break; case BIN_DISOWN: + if (jobtab[job].stat & STAT_SUPERJOB) { + jobtab[job].stat |= STAT_DISOWN; + continue; + } if (jobtab[job].stat & STAT_STOPPED) { char buf[20], *pids = ""; diff --git a/Src/zsh.h b/Src/zsh.h index 137b2a5..a5b4d8f 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1029,6 +1029,7 @@ struct job { #define STAT_BUILTIN (0x4000) /* job at tail of pipeline is a builtin */ #define STAT_SUBJOB_ORPHANED (0x8000) /* STAT_SUBJOB with STAT_SUPERJOB exited */ +#define STAT_DISOWN (0x10000) /* STAT_SUPERJOB with disown pending */ #define SP_RUNNING -1 /* fake status for jobs currently running */