zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: setopt monitor in non-interactive shell
@ 2006-08-21 21:01 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2006-08-21 21:01 UTC (permalink / raw)
  To: Zsh hackers list

There's a bug report on sourceforge:

>[ 1413647 ] using eval in monitor mode doesn't work!
>Submitted By:
>Thomas Eriksson - arne 	Date Submitted:
>2006-01-24 04:21
>Summary: (?)
>using eval in monitor mode doesn't work!
>I have tested the following code with zsh 4.2.6 on
>Ubuntu Breezy:
>
>Consider this trivial code
>
>#!/bin/zsh
>set -m
>eval /bin/echo foo bar
>## EOF
>
>Interpreting it with zsh will make zsh "hang" at the
>eval command, instead of executing echo!
>
>This does not seem to affect builtins.
>
>I have tried this on recent versions of 'bash' and
>'pdksh' with no problem.

The hang happens, because the shell hasn't properly set up its process
group because the usual interactive handling wasn't done; enabling the
monitor option made it think it could set the process group.  This
caused the child forked for /bin/echo (it's not specific to eval) to be
suspended in a way the parent shell wasn't prepared to handle.  Or
something.

The monitor option in zsh is tied to being in an interactive shell.  I
think the only answer, however unpleasing it may seem, is to make some
attempt but give up without trying to reinitialise the shell which is
the only way it's actually going to work in a case like this.

The code that makes "some attempt" is the same as that which tries to
set up the monitor option in the first place:  chances are the monitor
option wasn't set because this failed last time round, so I'm not sure
how useful this is.

I don't really know much about terminal handling.  If anyone else thinks
they can fix it properly please do so.

Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.30
diff -u -r1.30 options.c
--- Src/options.c	25 Jul 2006 18:10:38 -0000	1.30
+++ Src/options.c	21 Aug 2006 20:59:26 -0000
@@ -687,7 +687,16 @@
 	setuid(getuid());
 	setgid(getgid());
 #endif /* HAVE_SETUID */
-#ifndef JOB_CONTROL
+#ifdef JOB_CONTROL
+    } else if (!force && optno == MONITOR) {
+	if (opts[optno] == value)
+	    return 0;
+	if (interact && (SHTTY != -1)) {
+	    origpgrp = GETPGRP();
+	    acquire_pgrp();
+	} else
+	    return -1;
+#else
     } else if(optno == MONITOR && value) {
 	    return -1;
 #endif /* not JOB_CONTROL */

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-08-21 21:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-21 21:01 PATCH: setopt monitor in non-interactive shell 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).