zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Cc: Victor Villa <victormvm+debian@gmail.com>, 593426@bugs.debian.org
Subject: Re: Bug#593426: zsh: Status of background jobs not updated
Date: Wed, 18 Aug 2010 21:09:59 +0100	[thread overview]
Message-ID: <20100818210959.2a9d4d25@pws-pc> (raw)
In-Reply-To: <20100818182959.GA29785@scru.org>

On Wed, 18 Aug 2010 18:29:59 +0000
Clint Adams <schizo@debian.org> wrote:
> On Wed, Aug 18, 2010 at 02:51:48PM +1200, Victor Villa wrote:
> > After running a process in the background (by putting "&" at the end
> > of the command line) the output of "jobs" correctly shows the
> > process as "running". If I send the process a STOP signal with "kill
> > -STOP", the process stops and "jobs" shows the process as "suspended
> > (signal)".  The problem is that after sending a CONT signal to the
> > process (with kill -CONT), "jobs" still shows the process as
> > suspended, even though the process resumes (if it's a media file I
> > can hear it playing, for example.

Part of the problem is that we don't update the process status properly
when sending a SIGCONT.  That's fairly easy to fix, and it sounds like
it addresses the immediate issue.

However, we ought to be cleverer, since we don't get a signal when a
child gets a SIGCONT from outside the shell, which is perfectly
possible.  To handle that we'd need to use wait3() or waitpid() with
WNOHANG to see if the job was still stopped.  That's still fairly
straightforward, the problem is that if the job has just exited we then
need to update the job status as if we were in the SIGCHLD handler, and
that needs more thought to do it properly.  Probably not *that*
difficult.  I don't suppose anyone has an urge to learn about the signal
code?

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.77
diff -p -u -r1.77 jobs.c
--- Src/jobs.c	31 Jul 2010 22:03:41 -0000	1.77
+++ Src/jobs.c	18 Aug 2010 19:58:50 -0000
@@ -2217,7 +2217,7 @@ bin_kill(char *nam, char **argv, UNUSED(
 	    signal. */
 	    if (jobtab[p].stat & STAT_STOPPED) {
 		if (sig == SIGCONT)
-		    jobtab[p].stat &= ~STAT_STOPPED;
+		    makerunning(jobtab + p);
 		if (sig != SIGKILL && sig != SIGCONT && sig != SIGTSTP
 		    && sig != SIGTTOU && sig != SIGTTIN && sig != SIGSTOP)
 		    killjb(jobtab + p, SIGCONT);
@@ -2225,9 +2225,19 @@ bin_kill(char *nam, char **argv, UNUSED(
 	} else if (!isanum(*argv)) {
 	    zwarnnam("kill", "illegal pid: %s", *argv);
 	    returnval++;
-	} else if (kill(atoi(*argv), sig) == -1) {
-	    zwarnnam("kill", "kill %s failed: %e", *argv, errno);
-	    returnval++;
+	} else {
+	    int pid = atoi(*argv);
+	    if (kill(pid, sig) == -1) {
+		zwarnnam("kill", "kill %s failed: %e", *argv, errno);
+		returnval++;
+	    } else if (sig == SIGCONT) {
+		Job jn;
+		Process pn;
+		if (findproc(pid, &jn, &pn, 0)) {
+		    if (WIFSTOPPED(pn->status))
+			pn->status = SP_RUNNING;
+		}
+	    }
 	}
     }
     unqueue_signals();

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2010-08-18 20:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20100818025148.13456.14691.reportbug@salamander.skynet.lan>
2010-08-18 18:29 ` Clint Adams
2010-08-18 20:09   ` Peter Stephenson [this message]
2010-08-20  4:22     ` Bart Schaefer
2010-08-20  8:55       ` Peter Stephenson
2010-08-21  0:07         ` Peter Stephenson
2010-08-19 22:14 Jilles Tjoelker
2010-08-20  2:36 ` Bart Schaefer
2010-08-20 20:21   ` Jilles Tjoelker

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=20100818210959.2a9d4d25@pws-pc \
    --to=p.w.stephenson@ntlworld.com \
    --cc=593426@bugs.debian.org \
    --cc=victormvm+debian@gmail.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).