Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: non-interactive set -m



Eric Blake wrote:
> As far as I can tell, POSIX requires 'set -m' to work even in non-interactive
>  
> shells, if the shell implements the User Portability Utilities (UP) option.  
> POSIX is also explicit that 'set -b' shall default to disabled.  Therefore, I
>  
> claim that this demonstrates two bugs:
> 
> $ zsh -c 'emulate sh; echo $-; set -m && set +m'
> b
> zsh:set:1: can't change option: -m
> $ echo 1

The -b behaviour isn't a bug: use "emulate -R sh" to get all options,
including ones that don't affect syntax, reset to the emulation
defaults.  However, making the shell start up in zsh mode and switching
is increasing the complexity of what's going on; something like

  ARGV0=sh zsh -c 'echo $-'

is easier and the output should be empty.  (Alternatively, if you're not
starting from zsh, use a symbolic link to zsh.)

Part of my reason for suggesting that is the following.  It's true you
can't change the MONITOR option after the shell starts.  It's probably
fixable, but being able to switch back and forth might be complicated
(though I haven't looked in detail).  However, making MONITOR work at
startup isn't so hard: the following simple patch stops it being tied to
interactive mode.  As this has no effect unless you request MONITOR, it
won't cause problems elsewhere.  This would mean that

  ARGV0=sh zsh -mc '...'

will enable monitor mode at startup.  Note that you do need a tty or pty
of some sort (that's what SHTTY != -1 is testing), but that's probably
obvious from the way job control works.

What I don't know and haven't tested is whether MONITOR actually works
in a non-interative shell.  A simple test suggested it was basically OK.
If someone can investigate whether there are any problems with the
following patch I will see if they are easy to fix.

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.101
diff -u -r1.101 init.c
--- Src/init.c	1 Jul 2009 15:07:33 -0000	1.101
+++ Src/init.c	8 Jul 2009 08:49:21 -0000
@@ -486,7 +486,7 @@
      * process group leader.
      */
     mypid = (zlong)getpid();
-    if (opts[MONITOR] && interact && (SHTTY != -1)) {
+    if (opts[MONITOR] && (SHTTY != -1)) {
 	origpgrp = GETPGRP();
         acquire_pgrp(); /* might also clear opts[MONITOR] */
     } else


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author