about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-11-05 01:07:14 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-11-05 01:07:14 +0000
commit2a4f805f8e5e0cac3d97a209577f417672775d40 (patch)
tree63478281cf317432e95da6284f625f7ce1ae0336
parenta76b730530cd3b7c256383ac360711185b4306b7 (diff)
downloadzsh-2a4f805f8e5e0cac3d97a209577f417672775d40.tar.gz
zsh-2a4f805f8e5e0cac3d97a209577f417672775d40.tar.xz
zsh-2a4f805f8e5e0cac3d97a209577f417672775d40.zip
Merge of 22913: set $! after a "bg", too.
-rw-r--r--Doc/Zsh/params.yo3
-rw-r--r--Src/jobs.c16
2 files changed, 16 insertions, 3 deletions
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index fee05e338..bcd2ae23e 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -465,7 +465,8 @@ The following parameters are automatically set by the shell:
 startitem()
 vindex(!)
 item(tt(!) <S>)(
-The process ID of the last background command invoked.
+The process ID of the last command started in the background with tt(&),
+or put into the background with the tt(bg) builtin.
 )
 vindex(#)
 item(tt(#) <S>)(
diff --git a/Src/jobs.c b/Src/jobs.c
index b979bb8d6..ec11c747b 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1742,9 +1742,21 @@ bin_fg(char *name, char **argv, Options ops, int func)
 	case BIN_WAIT:
 	    if (func == BIN_BG)
 		jobtab[job].stat |= STAT_NOSTTY;
-	    if ((stopped = (jobtab[job].stat & STAT_STOPPED)))
+	    if ((stopped = (jobtab[job].stat & STAT_STOPPED))) {
 		makerunning(jobtab + job);
-	    else if (func == BIN_BG) {
+		if (func == BIN_BG) {
+		    /* Set $! to indicate this was backgrounded */
+		    Process pn = jobtab[job].procs;
+		    for (;;) {
+			Process next = pn->next;
+			if (!next) {
+			    lastpid = (zlong) pn->pid;
+			    break;
+			}
+			pn = next;
+		    }
+		}
+	    } else if (func == BIN_BG) {
 		/* Silly to bg a job already running. */
 		zwarnnam(name, "job already in background", NULL, 0);
 		thisjob = ocj;