From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43543-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.8 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.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id af8448f5 for ; Tue, 25 Sep 2018 10:38:25 +0000 (UTC) Received: (qmail 8029 invoked by alias); 25 Sep 2018 10:38:11 -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: 43543 Received: (qmail 13148 invoked by uid 1010); 25 Sep 2018 10:38:11 -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(-7.4/5.0):. Processed in 4.771211 secs); 25 Sep 2018 10:38:11 -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 20180925103801euoutp01514c423715cd7206a24bef8f9666235a~XnlP012533086630866euoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1537871881; bh=dxqlX0frTk3/PHiXxQItM3x3RrxAQjqMWJU68woilmU=; h=Date:From:To:Subject:In-Reply-To:References:From; b=snDxDmB+n/KFOkFppAncWaxnnbub9K8kpqjevz6ch9vO9RqNws/41wKAK+T+hdoew IG1h4tO2D4ig4DCVWfaIdk4I7Vxshol+Y1jm03xaDHt5WBW0gNrqabsOODonjqk5q2 1wrskQxuV55FyjfLAAVKItmyuxOkajHfOZu03TNs= X-AuditID: cbfec7f2-5c9ff70000001159-e4-5baa1008d807 Date: Tue, 25 Sep 2018 11:37:58 +0100 From: Peter Stephenson To: Subject: Re: long-standing tty related issue: wrapped Emacs not suspended In-Reply-To: <20180924205106.03ee3da6@pws-HP.localdomain> 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+NgFvrAIsWRmVeSWpSXmKPExsWy7djP87ocAquiDY4fkbQ42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGV0rrjIX/NCs2L1vC0sD4wv5LkZODgkBE4l5R7axdDFycQgJ rGCUaDh1jxHC6WOSWPRpChuE08skcXHZJlaYlv+z/zBDJJYzSjRNecIEV7Vjw2x2COcMo8Sv BSegyi4wStw8s5MRpJ9FQFWiY9c3MJtNwFBi6qbZYLaIgKTEtebTYLawgKfE98+/wfZxClhK LJ94HGgQBwe/gJDEhWZbiDPsJY7uOckEYvMKCEqcnPmEBcRmFpCX2P52DtheCYHPbBJrHu5i gSgqk9jWfIodotlF4kTzdah/hCVeHd8CFZeR+L9zPhNEczujxJpJr9khnB5GiU1H7zBCVFlL 9N2+yAhyEbOApsT6XfoQYUeJ41dXsoKEJQT4JG68FYQ4iE9i0rbpzBBhXomONiGIajWJHU1b GScwKs9C8sIsJC/MQpi/gJF5FaN4amlxbnpqsWFearlecWJucWleul5yfu4mRmA6OP3v+Kcd jF8vJR1iFOBgVOLhNXi5IlqINbGsuDL3EKMEB7OSCK8S36poId6UxMqq1KL8+KLSnNTiQ4zS HCxK4rx8WmnRQgLpiSWp2ampBalFMFkmDk6pBkaD7krt076cHFOsRNsZZ69apfZKgjlV9wlr fXXgyle2k490WfOsOatw8tXn6KUTtBfHT+lasaBzXtLUvG0Wu9zi7jcuW3x70ekqk8Docxsi mP/sPB61IenDL/sz7w8qmvRO60/wKF/5sftVQJXr5+Vme4MYGX4JXXv0J7M7Qer1ot9XdbfI 8HUrsRRnJBpqMRcVJwIAslyU2QMDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeLIzCtJLcpLzFFi42I5/e/4XV12gVXRBru2cVscbH7I5MDoserg B6YAxig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9 jK4VV5kLfmhW7N63haWB8YV8FyMnh4SAicT/2X+Yuxi5OIQEljJKfL1/jQ0iISPx6cpHdghb WOLPtS42iKJuJol5/05AOWcYJZZNPskI4VxglJgzfxsLSAuLgKpEx65vjCA2m4ChxNRNs8Fs EQFJiWvNp8FsYQFPie+ff7OC2LwCzhLXz65gBrE5BSwllk88DnXTM0aJ4+/OAg3l4OAXEJK4 0GwLcZK9xNE9J5kgegUlTs58AraXWUBH4sSqY8wQtrzE9rdzmCcwCs9CUjYLSdksJGULGJlX MYqklhbnpucWG+oVJ+YWl+al6yXn525iBMbFtmM/N+9gvLQx+BCjAAejEg/vjWcrooVYE8uK K3MPMUpwMCuJ8CrxrYoW4k1JrKxKLcqPLyrNSS0+xGgKDIyJzFKiyfnAmM0riTc0NTS3sDQ0 NzY3NrNQEuc9b1AZJSSQnliSmp2aWpBaBNPHxMEp1cDo0tdg9bZ+tsOxo5Yi+vVm2hc2ynpx u+wXLHuxnEfN8JHxaT1vDVnrxR2zmcUlM98XHWxSrc0rlZl/++uULB3xfnO1PP33+9eJXY7u eT7BZuZ7k9t/6k/XP+roat3qajzzueWMbwE3nkteWCcyIUDz980Hpf+nXT5nu7Xdx3XODI+E /c5rBH4osRRnJBpqMRcVJwIAZ3/6MKECAAA= Message-Id: <20180925103759eucas1p2a15709c7a9d8df72d8c390521a6999ab~XnlOUhOUG3250532505eucas1p2u@eucas1p2.samsung.com> X-CMS-MailID: 20180925103759eucas1p2a15709c7a9d8df72d8c390521a6999ab X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180924200327epcas5p16c59687fb2a9ac2ea8919ceab7705c02 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180924200327epcas5p16c59687fb2a9ac2ea8919ceab7705c02 References: <20180920123005.GA20647@zira.vinc17.org> <20180921175740.6ab97a81@pws-HP.localdomain> <20180924205106.03ee3da6@pws-HP.localdomain> Just for clarity, what I'm actually testing is the following. I'm using vi as a simpler alternative to emacs --- as Bart noted, emacs may have additional ishoos of its own. % foo() { vi; } % foo ^Z % bg # Not sure why bg loses the current job number but assuming this is # standard behaviour... % fg %1 This should cleanly restore a full-window vi, which it does after the last patch, but not before. Now read on. Or not. On Mon, 24 Sep 2018 20:51:06 +0100 Peter Stephenson wrote: > - Send SIGCONT when attaching a subjob to the TTY. This is because > its stoppedness is invisible to the user, who is (unknowlingly) only > directly manipulating the superjob, so the shell has to give a helping > hand. Comment added. After a bit more research: we have code to SIGTSTP the superjob if the subjob does get stopped (as it does here because of the SIGTTOU), but it doesn't trigger because it expects the job to be STAT_STOPPED already, whereas that's only going to happen further down the file. As it *is* going to happen I think the use of the somestopped flag is good enough, but as we return immediately we now need to change the job state here. (The superjob has some code to put itself back to sleep but I hope the interaction is benign.) Also, we need to mark the superjob (not just the subjob) as stopped at this point because if it's just the forked shell it's already suspended so there's no other place to hang that on. With that in place, the "stopped = 1" I added to fg/bg to send a possibly unnecessary SIGCONT isn't needed as the records are correct. (Hope you're enjoying this.) One remaining glitch is there's no message that the backgrounded job as been stopped again because we suppress messages for the job. This isn't particularly consistent given we do display the effect of the bg and the fg. Not sure what a consistent way forward would be here. > - Wait for subjob of superjob if waiting for the superjob, else the "fg" > makes the top-level shell continue immediately, so both jobs are running > at once. (The wait for the superjob returns when that exits, even > though the only process, the forked shell, is stopped at this point. > It's not clear to me this is correct --- see note on makerunning() > below. I think with this behaviour waiting for the subjob may be > superfluous, but I think it's correct anyway as the whole lot is > considered to be in the forground.) Logically, we should wait for the subjob first --- its exit should provoke the superjob into further action. So I've swapped it round. As before, the only way of teasing out problems will be to try this out, so I'll commit it. pws diff --git a/Src/jobs.c b/Src/jobs.c index c399f1d..f64b46b 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -459,19 +459,29 @@ update_job(Job jn) jn->ty = (struct ttyinfo *) zalloc(sizeof(struct ttyinfo)); gettyinfo(jn->ty); } - if (jn->stat & STAT_STOPPED) { - if (jn->stat & STAT_SUBJOB) { - /* If we have `cat foo|while read a; grep $a bar;done' - * and have hit ^Z, the sub-job is stopped, but the - * super-job may still be running, waiting to be stopped - * or to exit. So we have to send it a SIGTSTP. */ - int i; - - if ((i = super_job(job))) - killpg(jobtab[i].gleader, SIGTSTP); + if (jn->stat & STAT_SUBJOB) { + /* If we have `cat foo|while read a; grep $a bar;done' + * and have hit ^Z, the sub-job is stopped, but the + * super-job may still be running, waiting to be stopped + * or to exit. So we have to send it a SIGTSTP. */ + int i; + + if ((i = super_job(job))) { + killpg(jobtab[i].gleader, SIGTSTP); + /* + * Job may already be stopped if it consists of only the + * forked shell waiting for the subjob -- so mark as + * stopped immediately. This ensures we send it (and, + * crucially, the subjob, as the visible job used with + * fg/bg is the superjob) a SIGCONT if we need it. + */ + jobtab[i].stat |= STAT_CHANGED | STAT_STOPPED; } + jn->stat |= STAT_CHANGED | STAT_STOPPED; return; } + if (jn->stat & STAT_STOPPED) + return; } { /* job is done or stopped, remember return value */ lastval2 = val; @@ -1608,10 +1618,11 @@ waitjobs(void) Job jn = jobtab + thisjob; DPUTS(thisjob == -1, "No valid job in waitjobs."); - waitonejob(jn); + /* If there's a subjob, it should finish first. */ if (jn->stat & STAT_SUPERJOB) waitonejob(jobtab + jn->other); - + waitonejob(jn); + thisjob = -1; } @@ -2407,17 +2418,9 @@ bin_fg(char *name, char **argv, Options ops, int func) ((!jobtab[job].procs->next || (jobtab[job].stat & STAT_SUBLEADER) || killpg(jobtab[job].gleader, 0) == -1)) && - jobtab[jobtab[job].other].gleader) { + jobtab[jobtab[job].other].gleader) attachtty(jobtab[jobtab[job].other].gleader); - /* - * In case stopped by putting in background. - * Usually that's visible to the user, who - * can restart, but with a superjob this is done - * behind the scenes, so do it here. Should - * be harmless if not needed. - */ - stopped = 1; - } else + else attachtty(jobtab[job].gleader); } }