about summary refs log tree commit diff
path: root/Src/jobs.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-12-02 09:46:12 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-12-02 09:46:12 +0000
commit3206b8a2eac54b75a181859cd98130c5219c3126 (patch)
tree64de96a496ae31708bf9ba59065d83a62da600fb /Src/jobs.c
parentbc51b97d53d24e5d793d3219940de7daf60d2916 (diff)
downloadzsh-3206b8a2eac54b75a181859cd98130c5219c3126.tar.gz
zsh-3206b8a2eac54b75a181859cd98130c5219c3126.tar.xz
zsh-3206b8a2eac54b75a181859cd98130c5219c3126.zip
27442 plus tweak: wait returns status for $! even if exited
Diffstat (limited to 'Src/jobs.c')
-rw-r--r--Src/jobs.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Src/jobs.c b/Src/jobs.c
index d0916174f..9b7b053ee 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -104,6 +104,15 @@ int prev_errflag, prev_breaks, errbrk_saved;
 /**/
 int numpipestats, pipestats[MAX_PIPESTATS];
 
+/*
+ * The status associated with the process lastpid.
+ * -1 if not set and no associated lastpid
+ * -2 if lastpid is set and status isn't yet
+ * else the value returned by wait().
+ */
+/**/
+long lastpid_status;
+
 /* Diff two timevals for elapsed-time computations */
 
 /**/
@@ -1109,6 +1118,14 @@ addproc(pid_t pid, char *text, int aux, struct timeval *bgtime)
 {
     Process pn, *pnlist;
 
+    if (pid == lastpid && lastpid_status != -2L) {
+	/*
+	 * The status for the previous lastpid is invalid.
+	 * Presumably process numbers have wrapped.
+	 */
+	lastpid_status = -1L;
+    }
+
     DPUTS(thisjob == -1, "No valid job in addproc.");
     pn = (Process) zshcalloc(sizeof *pn);
     pn->pid = pid;
@@ -1845,6 +1862,9 @@ bin_fg(char *name, char **argv, Options ops, int func)
 		retval = waitforpid(pid, 1);
 		if (!retval)
 		    retval = lastval2;
+	    } else if (isset(POSIXJOBS) &&
+		       pid == lastpid && lastpid_status >= 0L) {
+		retval = (int)lastpid_status;
 	    } else {
 		zwarnnam(name, "pid %d is not a child of this shell", pid);
 		/* presumably lastval2 doesn't tell us a heck of a lot? */