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

Re: question about wait in interactive mode



Peter Stephenson <pws@xxxxxxx> wrote:
> This code:
> 
>   print | (echo & wait)
> 
> also hangs (it's the simplest version I've found:  the pipeline and
> the subshell are both necessary)

I tracked this down to the job table not being cleared properly in a
subshell, so the shell is waiting forever for a process which isn't a
child.

I noticed a couple of other bugs at the same time:

The code to find a new job was inefficient, since any job above maxjob is
guaranteed to be usable (very minor).

Also, the code to save jobs so that they can be reported in a subshell
saved the job in which it was running, which shouldn't be reported since it
isn't in normal use.  For example,

% print | (jobs)
[1]    running    print

doesn't make sense.  (At least, I don't think it does.  Actually, you
can argue that in an explicit subshell, i.e. with parentheses, you
shouldn't be saving jobs at all since, unlike with a pipeline, you've
explicitly told the shell you're using a subshell which won't
have any jobs of its own.)

This ought to go onto 4.2 as well as the main line.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.41
diff -u -r1.41 jobs.c
--- Src/jobs.c	15 Aug 2005 03:28:39 -0000	1.41
+++ Src/jobs.c	13 Oct 2005 17:37:25 -0000
@@ -1213,9 +1213,14 @@
 	int sz = oldmaxjob * sizeof(struct job);
 	oldjobtab = (struct job *)zalloc(sz);
 	memcpy(oldjobtab, jobtab, sz);
+
+	/* Don't report any job we're part of */
+	if (thisjob != -1 && thisjob < oldmaxjob)
+	    memset(oldjobtab+thisjob, 0, sizeof(struct job));
     }
 
-    memset(jobtab, 0, sizeof(jobtab)); /* zero out table */
+    memset(jobtab, 0, jobtabsize * sizeof(struct job)); /* zero out table */
+    maxjob = 0;
 }
 
 static int initnewjob(int i)
@@ -1241,9 +1246,11 @@
 {
     int i;
 
-    for (i = 1; i < jobtabsize; i++)
+    for (i = 1; i <= maxjob; i++)
 	if (!jobtab[i].stat)
 	    return initnewjob(i);
+    if (maxjob + 1 < jobtabsize)
+	return initnewjob(maxjob+1);
 
     if (expandjobtab())
 	return initnewjob(i);


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



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