* Re: question about wait in interactive mode
[not found] ` <EXCHANGE03zjwtBOmt900002b33@exchange03.csr.com>
@ 2005-10-13 17:47 ` Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2005-10-13 17:47 UTC (permalink / raw)
To: Radu Duta, zsh-workers
Peter Stephenson <pws@csr.com> 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@csr.com> 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-10-13 17:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20051005133459.GA25549@syskey.com>
[not found] ` <EXCHANGE03zjwtBOmt900002b33@exchange03.csr.com>
2005-10-13 17:47 ` question about wait in interactive mode Peter Stephenson
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).