zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: long-standing tty related issue: wrapped Emacs not suspended
Date: Wed, 26 Sep 2018 16:17:08 +0100	[thread overview]
Message-ID: <20180926151710eucas1p1a1bd97b6c7c43e24bdb0fd5798c6cd63~X-CRTpc1m1950519505eucas1p1f@eucas1p1.samsung.com> (raw)
In-Reply-To: <CAH+w=7ZmhsKwJTSU90gDrZy1FgJQDAfkYaLMmY8Eq=aSAYdQwg@mail.gmail.com>

On Tue, 25 Sep 2018 22:47:44 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
But if you ^Z a function and then background it, the parent still
> believes it to be running even though it has instantly stopped:
> 
> % e
> zsh: suspended  e
> % bg
> [1]  + continued  e
> % jobs
> [1]  + running    e

To get this to work, I had to hack printjobs().  There's another hack in
printjobs to do pretty much the reverse --- if you're in the superjob
and the last job is suspended, treat it as running, because that's the
subshell that's waiting for the subjob so it's suspension isn't
relevant.  However, in this case I'm actually printing the subjob state
as the most relevant so that works around that --- this also means
"jobs" lists the correct process as suspended.

I've also added a printjob() to the point where the subjob is suspended
to make it reflect the fact that, as far as the user is concerned,
everything is associated with the superjob.

I would say we are in danger of disappearing up our own backsides but I
think that happened long ago.

pws

diff --git a/Src/jobs.c b/Src/jobs.c
index f64b46b..8103f5c 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -466,8 +466,10 @@ update_job(Job jn)
 	     * or to exit. So we have to send it a SIGTSTP. */
 	    int i;
 
+	    jn->stat |= STAT_CHANGED | STAT_STOPPED;
 	    if ((i = super_job(job))) {
-		killpg(jobtab[i].gleader, SIGTSTP);
+		Job sjn = &jobtab[i];
+		killpg(sjn->gleader, SIGTSTP);
 		/*
 		 * Job may already be stopped if it consists of only the
 		 * forked shell waiting for the subjob -- so mark as
@@ -475,9 +477,20 @@ update_job(Job jn)
 		 * 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;
+		sjn->stat |= STAT_CHANGED | STAT_STOPPED;
+		if (isset(NOTIFY) && (sjn->stat & STAT_LOCKED) &&
+		    !(sjn->stat & STAT_NOPRINT)) {
+		    /*
+		     * Print the subjob state, which we don't usually
+		     * do, so the user knows something has stopped.
+		     * So as not to be confusing, we actually output
+		     * the user-visible superjob.
+		     */
+		    if (printjob(sjn, !!isset(LONGLISTJOBS), 0) &&
+			zleactive)
+			zleentry(ZLE_CMD_REFRESH);
+		}
 	    }
-	    jn->stat |= STAT_CHANGED | STAT_STOPPED;
 	    return;
 	}
 	if (jn->stat & STAT_STOPPED)
@@ -1035,15 +1048,34 @@ printjob(Job jn, int lng, int synch)
 	   "bogus job number, jn = %L, jobtab = %L, oldjobtab = %L",
 	   (long)jn, (long)jobtab, (long)oldjobtab);
 
-    if (jn->stat & STAT_NOPRINT) {
+    if (jn->stat & STAT_NOPRINT)
 	skip_print = 1;
-    }
 
     if (lng < 0) {
 	conted = 1;
 	lng = !!isset(LONGLISTJOBS);
     }
 
+    if (jn->stat & STAT_SUPERJOB &&
+	jn->other)
+    {
+	Job sjn = &jobtab[jn->other];
+	if (sjn->stat & STAT_STOPPED)
+	{
+	    /*
+	     * A subjob is stopped, which will prevent further excution
+	     * of the superjob, which the user wants to know about.  So
+	     * report the status of the subjob as if it were the
+	     * user-visible superjob.
+	     *
+	     * TBD: there may be other times we want to do this
+	     * which would, for example, remove the need for the
+	     * hack at the top of the loop over processes just below.
+	     */
+	    jn = sjn;
+	}
+    }
+
 /* find length of longest signame, check to see */
 /* if we really need to print this job          */
 

  parent reply	other threads:[~2018-09-26 15:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20 12:30 Vincent Lefevre
2018-09-20 15:43 ` Joey Pabalinas
2018-09-20 23:10   ` Vincent Lefevre
2018-09-21 16:57 ` Peter Stephenson
2018-09-21 23:14   ` Joey Pabalinas
2018-09-22  1:17   ` Bart Schaefer
2018-09-22  5:51     ` Joey Pabalinas
2018-09-22 18:54       ` Vincent Lefevre
2018-09-22 21:27         ` Joey Pabalinas
2018-09-23  7:21           ` Vincent Lefevre
2018-09-24 19:51   ` Peter Stephenson
2018-09-25 10:37     ` Peter Stephenson
2018-09-25 17:04       ` Daniel Shahaf
2018-09-26  5:47       ` Bart Schaefer
2018-09-26 13:41         ` Peter Stephenson
2018-09-26 15:17         ` Peter Stephenson [this message]
     [not found]         ` <20180926161708.39be6402@camnpupstephen.cam.scsc.local>
2018-10-02 15:32           ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20180926151710eucas1p1a1bd97b6c7c43e24bdb0fd5798c6cd63~X-CRTpc1m1950519505eucas1p1f@eucas1p1.samsung.com' \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).