about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2017-12-22 20:00:54 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2017-12-22 20:21:23 +0000
commit5f6a52c06ca956cf61eacd7f45f270899337d45e (patch)
treeb8743b8d42059b329ab6d65fb4019dba45566318
parent349c95765a030cf614c3c2a9fdc45941d3b115fc (diff)
downloadzsh-5f6a52c06ca956cf61eacd7f45f270899337d45e.tar.gz
zsh-5f6a52c06ca956cf61eacd7f45f270899337d45e.tar.xz
zsh-5f6a52c06ca956cf61eacd7f45f270899337d45e.zip
42156: new CHECK_RUNNING_JOBS option demanded by bash groupies
Also new job options.

Also suppress debug error if rows or columns are reported as zero as
this is normal without a physical terminal.
-rw-r--r--ChangeLog10
-rw-r--r--Doc/Zsh/options.yo17
-rw-r--r--Src/builtin.c3
-rw-r--r--Src/options.c1
-rw-r--r--Src/utils.c4
-rw-r--r--Src/zsh.h1
-rw-r--r--Test/W02jobs.ztst186
7 files changed, 217 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 1b9b0be68..5a3d0ec97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-12-22  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* dana: 42156 with tweak as per 42158: Doc/Zsh/options.yo,
+	Src/builtin.c, Src/options.c, Src/utils.c, Src/zsh.h,
+	Test/W02jobs.ztst: add CHECK_RUNNING_JOBS opion and job tests;
+	remove debug error when rows or columns are zero as this is
+	normal without a physical terminal.
+
+	* dana: 42156: Doc/Zsh/options.yo, Src/builtin.c,
+	Src/options.c, Src/zsh.h, Test/W02jobs.ztst: new
+	CHECK_RUNNING_JOBS option demanded by bash groupies.
+
 	* danda: 42155: Completion/Unix/Command/_ssh: various
 	improvements for OpenSSH.
 
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index d043cf398..25b3d5736 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -817,7 +817,7 @@ zsh sessions will all have the new entries from their history lists
 added to the history file, in the order that they exit.
 The file will still be periodically re-written to trim it when the
 number of lines grows 20% beyond the value specified by
-tt($SAVEHIST) (see also the HIST_SAVE_BY_COPY option).
+tt($SAVEHIST) (see also the tt(HIST_SAVE_BY_COPY) option).
 )
 pindex(BANG_HIST)
 pindex(NO_BANG_HIST)
@@ -1429,6 +1429,19 @@ ifnzman(the section Special Functions in noderef(Functions))\
 ifzman(the section SPECIAL FUNCTIONS in zmanref(zshmisc))
 is not counted for this purpose.
 )
+pindex(CHECK_RUNNING_JOBS)
+pindex(NO_CHECK_RUNNING_JOBS)
+pindex(CHECKRUNNINGJOBS)
+pindex(NOCHECKRUNNINGJOBS)
+cindex(exiting, checking running jobs when)
+cindex(logging out, checking running jobs when)
+item(tt(CHECK_RUNNING_JOBS) <Z>)(
+Check for both running and suspended jobs when tt(CHECK_JOBS) is enabled.
+When this option is disabled, zsh checks only for suspended jobs, which
+matches the default behavior of bash.
+
+This option has no effect unless tt(CHECK_JOBS) is set.
+)
 pindex(HUP)
 pindex(NO_HUP)
 pindex(NOHUP)
@@ -1443,7 +1456,7 @@ pindex(LONGLISTJOBS)
 pindex(NOLONGLISTJOBS)
 cindex(jobs, list format)
 item(tt(LONG_LIST_JOBS) (tt(-R)))(
-List jobs in the long format by default.
+Print job notifications in the long format by default.
 )
 pindex(MONITOR)
 pindex(NO_MONITOR)
diff --git a/Src/builtin.c b/Src/builtin.c
index f002b9912..0211f2721 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5594,7 +5594,8 @@ checkjobs(void)
 
     for (i = 1; i <= maxjob; i++)
 	if (i != thisjob && (jobtab[i].stat & STAT_LOCKED) &&
-	    !(jobtab[i].stat & STAT_NOPRINT))
+	    !(jobtab[i].stat & STAT_NOPRINT) &&
+	    (isset(CHECKRUNNINGJOBS) || jobtab[i].stat & STAT_STOPPED))
 	    break;
     if (i <= maxjob) {
 	if (jobtab[i].stat & STAT_STOPPED) {
diff --git a/Src/options.c b/Src/options.c
index 2b5795bab..590652ea9 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -111,6 +111,7 @@ static struct optname optns[] = {
 {{NULL, "chasedots",	      OPT_EMULATE},		 CHASEDOTS},
 {{NULL, "chaselinks",	      OPT_EMULATE},		 CHASELINKS},
 {{NULL, "checkjobs",	      OPT_EMULATE|OPT_ZSH},	 CHECKJOBS},
+{{NULL, "checkrunningjobs",   OPT_EMULATE|OPT_ZSH},	 CHECKRUNNINGJOBS},
 {{NULL, "clobber",	      OPT_EMULATE|OPT_ALL},	 CLOBBER},
 {{NULL, "combiningchars",     0},			 COMBININGCHARS},
 {{NULL, "completealiases",    0},			 COMPLETEALIASES},
diff --git a/Src/utils.c b/Src/utils.c
index 4c0ebe6f5..74fdac31f 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1832,7 +1832,7 @@ adjustlines(int signalled)
     else
 	shttyinfo.winsize.ws_row = zterm_lines;
 #endif /* TIOCGWINSZ */
-    if (zterm_lines <= 0) {
+    if (zterm_lines < 0) {
 	DPUTS(signalled, "BUG: Impossible TIOCGWINSZ rows");
 	zterm_lines = tclines > 0 ? tclines : 24;
     }
@@ -1856,7 +1856,7 @@ adjustcolumns(int signalled)
     else
 	shttyinfo.winsize.ws_col = zterm_columns;
 #endif /* TIOCGWINSZ */
-    if (zterm_columns <= 0) {
+    if (zterm_columns < 0) {
 	DPUTS(signalled, "BUG: Impossible TIOCGWINSZ cols");
 	zterm_columns = tccolumns > 0 ? tccolumns : 80;
     }
diff --git a/Src/zsh.h b/Src/zsh.h
index 22ae95480..92f75769a 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2339,6 +2339,7 @@ enum {
     CHASEDOTS,
     CHASELINKS,
     CHECKJOBS,
+    CHECKRUNNINGJOBS,
     CLOBBER,
     APPENDCREATE,
     COMBININGCHARS,
diff --git a/Test/W02jobs.ztst b/Test/W02jobs.ztst
new file mode 100644
index 000000000..65b860072
--- /dev/null
+++ b/Test/W02jobs.ztst
@@ -0,0 +1,186 @@
+# Tests for interactive job control
+
+%prep
+
+  if [[ $OSTYPE == cygwin ]]; then
+    ZTST_unimplemented='the zsh/zpty module does not work on Cygwin'
+  elif zmodload zsh/zpty 2> /dev/null; then
+    zpty_start() {
+      export PS1= PS2=
+      zpty -d
+      zpty zsh "${(q)ZTST_testdir}/../Src/zsh -fiV +Z"
+    }
+    zpty_input() {
+      zpty -w zsh "${(F)@}" $'\n'
+    }
+    zpty_stop() {
+      # exit twice in case of check_jobs
+      zpty -w zsh $'exit\nexit\n'
+      # zpty gives no output when piped without these braces (?)
+      { zpty -r zsh } | sed $'/[^[:space:]]/!d; s/\r$//;'
+      zpty -d
+      :
+    }
+  else
+    ZTST_unimplemented='the zsh/zpty module is not available'
+  fi
+
+%test
+
+  zpty_start
+  zpty_input 'setopt no_long_list_jobs'
+  zpty_input ': &'
+  zpty_input 'wait'
+  zpty_stop
+0:job notification with no_long_list_jobs
+*>\[1] [0-9]##
+*>\[1]  + done[[:space:]]##:
+
+  zpty_start
+  zpty_input 'setopt long_list_jobs'
+  zpty_input ': &'
+  zpty_input 'wait'
+  zpty_stop
+0:job notification with long_list_jobs
+*>\[1] [0-9]##
+*>\[1]  + [0-9]## done[[:space:]]##:
+
+  zpty_start
+  zpty_input 'setopt no_hup no_check_jobs'
+  zpty_input 'sleep 3 &'
+  zpty_stop
+0:running job with no_hup + no_check_jobs
+*>\[1] [0-9]##
+
+  zpty_start
+  zpty_input 'setopt no_check_jobs'
+  zpty_input 'sleep 3 &'
+  zpty_stop
+0:running job with no_check_jobs
+*>\[1] [0-9]##
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'setopt check_jobs no_check_running_jobs'
+  zpty_input 'sleep 3 &'
+  zpty_stop
+0:running job with check_jobs + no_check_running_jobs
+*>\[1] [0-9]##
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'setopt check_jobs check_running_jobs'
+  zpty_input 'sleep 3 &'
+  zpty_stop
+0:running job with check_jobs + check_running_jobs
+*>\[1] [0-9]##
+*>zsh:*running jobs*
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'setopt check_jobs no_check_running_jobs'
+  zpty_input 'sleep 3'
+  sleep 0.1
+  zpty_input $'\C-z'
+  zpty_stop
+0:suspended job with check_jobs + no_check_running_jobs
+*>zsh:*(stopped|suspended)*sleep*
+*>zsh:*(stopped|suspended) jobs*
+# no 'SIGHUPed' message for suspended jobs
+
+  zpty_start
+  zpty_input 'setopt check_jobs check_running_jobs'
+  zpty_input 'sleep 3'
+  sleep 0.1
+  zpty_input $'\C-z'
+  zpty_stop
+0:suspended job with check_jobs + check_running_jobs
+*>zsh:*(stopped|suspended)*sleep*
+*>zsh:*(stopped|suspended) jobs*
+# no 'SIGHUPed' message for suspended jobs
+
+  zpty_start
+  zpty_input 'sleep 5 & sleep 4 & sleep 3 &'
+  zpty_input 'jobs'
+  zpty_stop
+0:`jobs` (misc.) with multiple running jobs
+*>\[1] [0-9]##
+*>\[2] [0-9]##
+*>\[3] [0-9]##
+*>\[1]    running*sleep 5*
+*>\[2]  - running*sleep 4*
+*>\[3]  + running*sleep 3*
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'sleep 3 &'
+  zpty_input 'jobs -l'
+  zpty_input 'jobs -p'
+  zpty_stop
+0:`jobs -l` and `jobs -p` with running job
+*>\[1] [0-9]##
+*>\[1]  + [0-9]## running*sleep*
+*>\[1]  + [0-9]## running*sleep*
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'sleep 3 &'
+  zpty_input 'jobs -d'
+  zpty_stop
+0:`jobs -d` with running job
+*>\[1] [0-9]##
+*>\[1]  + running*sleep*
+*>\(pwd : ?*\)
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'sleep 3 &'
+  zpty_input 'jobs -r'
+  zpty_input 'print -- -'
+  zpty_input 'jobs -s'
+  zpty_stop
+0:`jobs -r` and `jobs -s` with running job
+*>\[1] [0-9]##
+*>\[1]  + running*sleep*
+*>-
+*>zsh:*SIGHUPed*
+
+  zpty_start
+  zpty_input 'sleep 5'
+  sleep 0.1
+  zpty_input $'\C-z'
+  zpty_input 'jobs -r'
+  zpty_input 'print -- -'
+  zpty_input 'jobs -s'
+  zpty_stop
+0:`jobs -r` and `jobs -s` with suspended job
+*>zsh:*(stopped|suspended)*sleep*
+*>-
+*>\[1]  + (stopped|suspended)*sleep*
+# no 'SIGHUPed' message for suspended jobs
+
+  zpty_start
+  zpty_input 'sleep 10 & sleep 9 & sleep 8 & sleep 7 &'
+  sleep 0.1
+  zpty_input 'kill %4'
+  sleep 0.1
+  zpty_input 'kill -HUP %3'
+  sleep 0.1
+  zpty_input 'kill -INT %2'
+  sleep 0.1
+  zpty_input 'kill -KILL %1'
+  sleep 0.1
+  zpty_stop
+0:various `kill` signals with multiple running jobs
+*>\[1] [0-9]##
+*>\[2] [0-9]##
+*>\[3] [0-9]##
+*>\[4] [0-9]##
+*>\[4]  ? terminate*sleep*
+*>\[3]  ? hangup*sleep*
+*>\[2]  ? interrupt*sleep*
+*>\[1]  ? kill*sleep*
+
+%clean
+
+  zmodload -ui zsh/zpty