Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: killing suspended jobs makes zsh hang after 47d1215



On Jun 12,  7:22am, Bart Schaefer wrote:
}
} ----------------------------
} revision 1.80
} date: 2011/04/01 11:02:16;  author: pws;  state: Exp;  lines: +18 -1
} Stef van Vlierberghe: 28965 (as posted in 28967):
} findproc() should not return processes not marked as SP_RUNNING
} ----------------------------
} 
} Evidently there are in fact cases where we need to find jobs that are
} not running.

The specific bug is fixed by the patch below, but I wonder if there are
other job status that need to be tested here as well.

Index: jobs.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/jobs.c,v
retrieving revision 1.30
diff -c -r1.30 jobs.c
--- jobs.c	1 Jun 2011 06:40:00 -0000	1.30
+++ jobs.c	12 Jun 2011 14:55:25 -0000
@@ -189,7 +189,8 @@
 	     * the termination of the process which pid we were supposed
 	     * to return in a different job.
 	     */
-	    if (pn->pid == pid && pn->status == SP_RUNNING) {
+	    if (pn->pid == pid && (pn->status == SP_RUNNING ||
+				   WIFSTOPPED(pn->status))) {
 		*pptr = pn;
 		*jptr = jobtab + i;
 		return 1;


Here are backtraces showing how we reach findproc() with the patch above
NOT YET applied [line number in findproc is inconsequential, I stepped
through to make sure of the return value].

When the job gets stopped:

(gdb) where
#0  findproc (pid=26597, jptr=0xbff08180, pptr=0xbff0817c, aux=0)
    at ../../zsh-4.0/Src/jobs.c:193
#1  0x080b175b in wait_for_processes () at ../../zsh-4.0/Src/signals.c:493
#2  0x080b19aa in zhandler (sig=17) at ../../zsh-4.0/Src/signals.c:584
#3  <signal handler called>
#4  0x007067a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#5  0x00747e6c in sigsuspend () from /lib/tls/libc.so.6
#6  0x080b15f6 in signal_suspend (sig=17, wait_cmd=0)
    at ../../zsh-4.0/Src/signals.c:373
#7  0x0808160e in zwaitjob (job=1, wait_cmd=0)
    at ../../zsh-4.0/Src/jobs.c:1317
#8  0x080817e5 in waitjobs () at ../../zsh-4.0/Src/jobs.c:1362
#9  0x08061ee0 in execpline (state=0xbff08cf0, slcode=4098, how=18, last1=0)
    at ../../zsh-4.0/Src/exec.c:1500
#10 0x080613e8 in execlist (state=0xbff08cf0, dont_change_job=0, exiting=0)
    at ../../zsh-4.0/Src/exec.c:1207
#11 0x08060e7e in execode (p=0xb7d834b8, dont_change_job=0, exiting=0, 
    context=0x813359b "toplevel") at ../../zsh-4.0/Src/exec.c:1028
#12 0x0807ac02 in loop (toplevel=1, justonce=0)
    at ../../zsh-4.0/Src/init.c:185
#13 0x0807d9db in zsh_main (argc=2, argv=0xbff08e44)
    at ../../zsh-4.0/Src/init.c:1528
#14 0x0804b386 in main (argc=2, argv=0xbff08e44)
    at ../../zsh-4.0/Src/main.c:93

Here findproc() returns 1.

After the job is killed with "kill %" there are two findproc() calls,
both of which return 0.

192		    if (pn->pid == pid && pn->status == SP_RUNNING) {
(gdb) p pn->status
$2 = 5247

(gdb) where
#0  findproc (pid=26597, jptr=0xbffe0d18, pptr=0xbffe0d14, aux=0)
    at ../../zsh-4.0/Src/jobs.c:200
#1  0x080b175b in wait_for_processes () at ../../zsh-4.0/Src/signals.c:493
#2  0x080b19aa in zhandler (sig=17) at ../../zsh-4.0/Src/signals.c:584
#3  <signal handler called>
#4  0x007067a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#5  0x00747d39 in sigprocmask () from /lib/tls/libc.so.6
#6  0x080b1533 in signal_unblock (set={__val = {65536, 0 <repeats 31 times>}})
    at ../../zsh-4.0/Src/signals.c:254
#7  0x080624f3 in execpline (state=0xbffe1830, slcode=4098, how=18, last1=0)
    at ../../zsh-4.0/Src/exec.c:1587
#8  0x080613e8 in execlist (state=0xbffe1830, dont_change_job=0, exiting=0)
    at ../../zsh-4.0/Src/exec.c:1207
#9  0x08060e7e in execode (p=0xb7d6a4d0, dont_change_job=0, exiting=0, 
    context=0x813359b "toplevel") at ../../zsh-4.0/Src/exec.c:1028
#10 0x0807ac02 in loop (toplevel=1, justonce=0)
    at ../../zsh-4.0/Src/init.c:185
#11 0x0807d9db in zsh_main (argc=2, argv=0xbffe1984)
    at ../../zsh-4.0/Src/init.c:1528
#12 0x0804b386 in main (argc=2, argv=0xbffe1984)
    at ../../zsh-4.0/Src/main.c:93

(gdb) where
#0  findproc (pid=26597, jptr=0xbffe0d18, pptr=0xbffe0d14, aux=1)
    at ../../zsh-4.0/Src/jobs.c:201
#1  0x080b17c7 in wait_for_processes () at ../../zsh-4.0/Src/signals.c:503
#2  0x080b19aa in zhandler (sig=17) at ../../zsh-4.0/Src/signals.c:584
#3  <signal handler called>
#4  0x007067a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#5  0x00747d39 in sigprocmask () from /lib/tls/libc.so.6
#6  0x080b1533 in signal_unblock (set={__val = {65536, 0 <repeats 31 times>}})
    at ../../zsh-4.0/Src/signals.c:254
#7  0x080624f3 in execpline (state=0xbffe1830, slcode=4098, how=18, last1=0)
    at ../../zsh-4.0/Src/exec.c:1587
#8  0x080613e8 in execlist (state=0xbffe1830, dont_change_job=0, exiting=0)
    at ../../zsh-4.0/Src/exec.c:1207
#9  0x08060e7e in execode (p=0xb7d6a4d0, dont_change_job=0, exiting=0, 
    context=0x813359b "toplevel") at ../../zsh-4.0/Src/exec.c:1028
#10 0x0807ac02 in loop (toplevel=1, justonce=0)
    at ../../zsh-4.0/Src/init.c:185
#11 0x0807d9db in zsh_main (argc=2, argv=0xbffe1984)
    at ../../zsh-4.0/Src/init.c:1528
#12 0x0804b386 in main (argc=2, argv=0xbffe1984)
    at ../../zsh-4.0/Src/main.c:93

With my patch then applied, findproc() returns 1 in the middle trace above,
which causes the job status to be updated.

-- 



Messages sorted by: Reverse Date, Date, Thread, Author