about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-06-27 11:22:04 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-06-27 11:22:04 +0000
commitb275190ff41ce261d9ec8bf6d984191252a1320f (patch)
tree5a759ec5c9ff88d4bab610f055db43642311b80b
parentb053d02cdb782f02e85b540b3fc0e2a70faa5695 (diff)
downloadzsh-b275190ff41ce261d9ec8bf6d984191252a1320f.tar.gz
zsh-b275190ff41ce261d9ec8bf6d984191252a1320f.tar.xz
zsh-b275190ff41ce261d9ec8bf6d984191252a1320f.zip
add autocontinue option to automatically make stopped jos running when they are being disowned; make that the default for `%job &!' and `%job &|' (15115)
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/builtins.yo6
-rw-r--r--Doc/Zsh/options.yo8
-rw-r--r--Src/exec.c10
-rw-r--r--Src/jobs.c14
-rw-r--r--Src/options.c1
-rw-r--r--Src/zsh.h1
7 files changed, 44 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index eba0d6392..81ec146c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-06-27  Sven Wischnowsky  <wischnow@zsh.org>
+
+	* 15115: Doc/Zsh/builtins.yo, Doc/Zsh/options.yo, Src/exec.c,
+	Src/jobs.c, Src/options.c, Src/zsh.h: add autocontinue option
+	to automatically make stopped jos running when they are being
+	disowned; make that the default for `%job &!' and `%job &|'
+
 2001-06-26  Andrej Borsenkow  <bor@zsh.org>
 
 	* 15099: Test/D03procsubst.ztst, Test/ztst.zsh: add some support
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index a65af889e..1c33326eb 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -230,6 +230,12 @@ Remove the specified var(job)s from the job table; the shell will
 no longer report their status, and will not complain if you
 try to exit an interactive shell with them running or stopped.
 If no var(job) is specified, disown the current job.
+
+If the var(job)s are currently stopped and the tt(AUTO_CONTINUE) option
+is not set, a warning is printed containing information about how to
+make them running after they have been disowned.  If one of the latter
+two forms is used, the var(job)s will automatically be made running,
+independent of the setting of the tt(AUTO_CONTINUE) option.
 )
 findex(echo)
 item(tt(echo) [ tt(-neE) ] [ var(arg) ... ])(
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 564e6701b..d2d952386 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -91,6 +91,14 @@ If a command is issued that can't be executed as a normal command,
 and the command is the name of a directory, perform the tt(cd)
 command to that directory.
 )
+pindex(AUTO_CONTINUE)
+cindex(jobs, continuing automatically)
+cindex(continuing jobs automatically)
+item(tt(AUTO_CONT))(
+With this option set, stopped jobs that are removed from the job table
+with the tt(disown) builtin command are automatically sent a tt(CONT)
+signal to make them running.
+)
 pindex(AUTO_LIST)
 cindex(completion, listing choices)
 item(tt(AUTO_LIST) (tt(-9)) <D>)(
diff --git a/Src/exec.c b/Src/exec.c
index 625c376b7..91ce74e57 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1645,7 +1645,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
     int nullexec = 0, assign = 0, forked = 0;
     int is_shfunc = 0, is_builtin = 0, is_exec = 0;
     /* Various flags to the command. */
-    int cflags = 0, checked = 0;
+    int cflags = 0, checked = 0, oautocont = opts[AUTOCONTINUE];
     LinkList redir;
     wordcode code;
     Wordcode beg = state->pc, varspc;
@@ -1680,6 +1680,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
      * reference to a job in the job table.                */
     if (type == WC_SIMPLE && args && nonempty(args) &&
 	*(char *)peekfirst(args) == '%') {
+        if (how & Z_DISOWN)
+            opts[AUTOCONTINUE] = 1;
 	pushnode(args, dupstring((how & Z_DISOWN)
 				 ? "disown" : (how & Z_ASYNC) ? "bg" : "fg"));
 	how = Z_SYNC;
@@ -1833,6 +1835,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		if (cflags & BINF_BUILTIN) {
 		    zwarn("no such builtin: %s", cmdarg, 0);
 		    lastval = 1;
+                    opts[AUTOCONTINUE] = oautocont;
 		    return;
 		}
 		break;
@@ -1856,6 +1859,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 
     if (errflag) {
 	lastval = 1;
+        opts[AUTOCONTINUE] = oautocont;
 	return;
     }
 
@@ -1899,6 +1903,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 
     if (errflag) {
 	lastval = 1;
+        opts[AUTOCONTINUE] = oautocont;
 	return;
     }
 
@@ -1981,6 +1986,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	if ((pid = zfork()) == -1) {
 	    close(synch[0]);
 	    close(synch[1]);
+            opts[AUTOCONTINUE] = oautocont;
 	    return;
 	} if (pid) {
 	    close(synch[1]);
@@ -2006,6 +2012,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		}
 	    }
 	    addproc(pid, text);
+            opts[AUTOCONTINUE] = oautocont;
 	    return;
 	}
 	/* pid == 0 */
@@ -2373,6 +2380,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 
     zsfree(STTYval);
     STTYval = 0;
+    opts[AUTOCONTINUE] = oautocont;
 }
 
 /* Arrange to have variables restored. */
diff --git a/Src/jobs.c b/Src/jobs.c
index 50002d28f..f462a0ae8 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1215,7 +1215,7 @@ init_hackzero(char **argv, char **envp)
 int
 bin_fg(char *name, char **argv, char *ops, int func)
 {
-    int job, lng, firstjob = -1, retval = 0;
+    int job, lng, firstjob = -1, retval = 0, ofunc = func;
 
     if (ops['Z']) {
 	int len;
@@ -1299,6 +1299,8 @@ bin_fg(char *name, char **argv, char *ops, int func)
     for (; (firstjob != -1) || *argv; (void)(*argv && argv++)) {
 	int stopped, ocj = thisjob;
 
+        func = ofunc;
+
 	if (func == BIN_WAIT && isanum(*argv)) {
 	    /* wait can take a pid; the others can't. */
 	    pid_t pid = (long)atoi(*argv);
@@ -1326,6 +1328,13 @@ bin_fg(char *name, char **argv, char *ops, int func)
 	    unqueue_signals();
 	    return 1;
 	}
+        /* If AUTO_CONTINUE is set (automatically make stopped jobs running
+         * on disown), we actually do a bg and then delete the job table entry. */
+
+        if (isset(AUTOCONTINUE) && func == BIN_DISOWN &&
+            jobtab[job].stat & STAT_STOPPED)
+            func = BIN_BG;
+
 	/* We have a job number.  Now decide what to do with it. */
 	switch (func) {
 	case BIN_FG:
@@ -1386,7 +1395,8 @@ bin_fg(char *name, char **argv, char *ops, int func)
 	    if (func != BIN_BG) {
 		waitjobs();
 		retval = lastval2;
-	    }
+	    } else if (ofunc == BIN_DISOWN)
+	        deletejob(jobtab + job);
 	    break;
 	case BIN_JOBS:
 	    printjob(job + jobtab, lng, 2);
diff --git a/Src/options.c b/Src/options.c
index 2c63f194a..cd45b31e9 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -75,6 +75,7 @@ static struct optname optns[] = {
 {NULL, "alwaystoend",	      0,			 ALWAYSTOEND},
 {NULL, "appendhistory",	      OPT_ALL,			 APPENDHISTORY},
 {NULL, "autocd",	      OPT_EMULATE,		 AUTOCD},
+{NULL, "autocontinue",	      0,			 AUTOCONTINUE},
 {NULL, "autolist",	      OPT_ALL,			 AUTOLIST},
 {NULL, "automenu",	      OPT_ALL,			 AUTOMENU},
 {NULL, "autonamedirs",	      0,			 AUTONAMEDIRS},
diff --git a/Src/zsh.h b/Src/zsh.h
index 5ab5661d1..5014099ce 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1314,6 +1314,7 @@ enum {
     ALWAYSTOEND,
     APPENDHISTORY,
     AUTOCD,
+    AUTOCONTINUE,
     AUTOLIST,
     AUTOMENU,
     AUTONAMEDIRS,