about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-10-13 17:49:59 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-10-13 17:49:59 +0000
commit4a2f8d92e7c3ced677c0a4257c3e017bdf6c00d6 (patch)
treea0af99885b8a170e4f6fd56d5104b9c97788b310
parent3c37057c34d975ada2e9e6590845732677e77104 (diff)
downloadzsh-4a2f8d92e7c3ced677c0a4257c3e017bdf6c00d6.tar.gz
zsh-4a2f8d92e7c3ced677c0a4257c3e017bdf6c00d6.tar.xz
zsh-4a2f8d92e7c3ced677c0a4257c3e017bdf6c00d6.zip
21872: job accounting in subshells was screwy
-rw-r--r--ChangeLog5
-rw-r--r--Src/jobs.c11
2 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7bbcb2add..80013481e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2005-10-13  Peter Stephenson  <pws@csr.com>
 
+	* 21872: Src/jobs.c: job table wasn't cleared properly in
+	subshells, possibly causing shell to hang; more efficient
+	search for free job entry; don't record current job for
+	use in saved job table.
+
 	* 21871: Src/exec.c, Src/glob.c, Src/params.c, Src/subst.c,
 	Src/utils.c, Src/zsh.h, Src/ztype.h, Src/Zle/compcore.c,
 	Src/Zle/compctl.c, Src/Zle/zle_tricky.c: replace INULL() with
diff --git a/Src/jobs.c b/Src/jobs.c
index 9d7d2aace..96250e84f 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1213,9 +1213,14 @@ clearjobtab(int monitor)
 	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 @@ initjob(void)
 {
     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);