zsh-workers
 help / color / mirror / code / Atom feed
* Re: jobs command in precmd
       [not found] <20000628113611.A20108@rambo.its.tudelft.nl>
@ 2000-06-28 10:20 ` Peter Stephenson
  2000-06-29  9:25   ` PATCH: " Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2000-06-28 10:20 UTC (permalink / raw)
  To: Rob Egelink, Zsh hackers list

> Hello *,
> 
> When I put the 'jobs' builtin command in my precmd function, zsh
> exits immediately without giving me a warning that I still have
> background jobs.
> 
> I found out that zsh exits without a warning if the previous command
> was the jobs command.
> 
> But in my precmd function there are many commands after the jobs
> command.

The shell has a flag (which happens to be called stopmsg) to tell it that
you've just looked at your jobs, and hence don't need to be warned again.
The main use of this is that you need to be able to ignore the `you have
XXX jobs' messages, otherwise you couldn't leave the shell at all.
However, it's assumed that the `jobs' command also tells you all you need
to know, so you can exit straight after.  (You probably know all this.)

The real difficulty is that the stopmsg is only reset when the shell gets
back to the main command loop, i.e. after executing some block of
commands on a single line.  Arguably this is correct as far as it goes,
since it doesn't matter how you see the message from `jobs' --- for
example, you might have buried it inside your own shell function.  But the
case of precmd is a bit special, since effectively it all happens without
your knowing.  Maybe simply saving and restoring stopmsg when executing
precmd would be enough.  I don't have time to go into the details right
now, however.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* PATCH: Re: jobs command in precmd
  2000-06-28 10:20 ` jobs command in precmd Peter Stephenson
@ 2000-06-29  9:25   ` Peter Stephenson
  2000-06-29  9:41     ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2000-06-29  9:25 UTC (permalink / raw)
  To: Zsh hackers list, Rob Egelink

> Maybe simply saving and restoring stopmsg when executing
> precmd would be enough.

This seems to be OK; here's the patch for the latest code in CVS.  I'll
send a patch for 3.0.8, too.

The last hunk keeps variables in read_poll() under control; it should
patch against 3.1.9 or 3.1.9-dev-1 if that's left out.

I couldn't find any description of the current logic for checking jobs, so
I added a short description to the CHECK_JOBS option.

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.8
diff -u -r1.8 options.yo
--- Doc/Zsh/options.yo	2000/05/24 17:20:26	1.8
+++ Doc/Zsh/options.yo	2000/06/29 09:21:46
@@ -244,8 +244,14 @@
 cindex(logging out, checking jobs when)
 item(tt(CHECK_JOBS) <Z>)(
 Report the status of background and suspended jobs before exiting a shell
-with job control.  tt(NO_CHECK_JOBS) is best used only in combination with
-tt(NO_HUP), else such jobs will be killed automatically.
+with job control; a second attempt to exit the shell will succeed.
+tt(NO_CHECK_JOBS) is best used only in combination with tt(NO_HUP), else
+such jobs will be killed automatically.
+
+The check is omitted if the commands run from the previous command line
+included a `tt(jobs)' command, since it is assumed the user is aware that
+there are background or suspended jobs.  A `tt(jobs)' command run from the
+tt(precmd) function is not counted for this purpose.
 )
 pindex(CLOBBER)
 cindex(clobbering, of files)
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.9
diff -u -r1.9 utils.c
--- Src/utils.c	2000/06/26 21:27:08	1.9
+++ Src/utils.c	2000/06/29 09:21:46
@@ -644,11 +644,16 @@
     /* If a shell function named "precmd" exists, *
      * then execute it.                           */
     if ((prog = getshfunc("precmd")) != &dummy_eprog) {
-	int osc = sfcontext;
+	/*
+	 * Save stopmsg, since user doesn't get a chance to respond
+	 * to a list of jobs generated in precmd.
+	 */
+	int osc = sfcontext, osm = stopmsg;
 
 	sfcontext = SFC_HOOK;
 	doshfunc("precmd", prog, NULL, 0, 1);
 	sfcontext = osc;
+	stopmsg = osm;
     }
     if (errflag)
 	return;
@@ -1316,12 +1321,13 @@
     int ret = 0;
     long mode = -1;
     char c;
-#ifdef FIONREAD
-    int val;
-#endif
 #ifdef HAVE_SELECT
     fd_set foofd;
     struct timeval expire_tv;
+#else
+#ifdef FIONREAD
+    int val;
+#endif
 #endif
 #ifdef HAS_TIO
     struct ttyinfo ti;

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Re: jobs command in precmd
  2000-06-29  9:25   ` PATCH: " Peter Stephenson
@ 2000-06-29  9:41     ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2000-06-29  9:41 UTC (permalink / raw)
  To: Zsh hackers list, Rob Egelink

I wrote:
> > Maybe simply saving and restoring stopmsg when executing
> > precmd would be enough.
> 
> This seems to be OK; here's the patch for the latest code in CVS.  I'll
> send a patch for 3.0.8, too.

here it is... there's no CHECK_JOBS option here.

> +	/*
> +	 * Save stopmsg, since user doesn't get a chance to respond
> +	 * to a list of jobs generated in precmd.
> +	 */

This wasn't really true, of course, since you get precmd just before the
command.  But I think it's reasonable to expect some conscious action on
the part of the user before overriding the check.

--- Src/utils.c.old	Thu Jun 29 10:25:58 2000
+++ Src/utils.c	Thu Jun 29 10:28:33 2000
@@ -595,8 +595,15 @@
 
     /* If a shell function named "precmd" exists, *
      * then execute it.                           */
-    if ((list = getshfunc("precmd")))
+    if ((list = getshfunc("precmd"))) {
+	/*
+	 * Save stopmsg since the user should type `jobs' themself
+	 * to turn off the exit check.
+	 */
+	int osm = stopmsg;
 	doshfunc(list, NULL, 0, 1);
+	stopmsg = osm;
+    }
     if (errflag)
 	return;
 
-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-06-29  9:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20000628113611.A20108@rambo.its.tudelft.nl>
2000-06-28 10:20 ` jobs command in precmd Peter Stephenson
2000-06-29  9:25   ` PATCH: " Peter Stephenson
2000-06-29  9:41     ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).