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

Re: non-interactive set -m



On Fri, 10 Jul 2009 03:32:59 +0000 (UTC)
Eric Blake <ebb9@xxxxxxx> wrote:
> Eric Blake <ebb9 <at> byu.net> writes:
> > > $ Src/zsh -c '(set -m); echo $?'
> > zsh:set:1: can't change option: -m
>
> $ zsh -ci '(set -m); echo $?'
> zsh:set:1: can't change option: -m

This is getting murkier.

When we enter a subshell, we close the file descriptor pointing to the
terminal.  It's not clear to me this is strictly necessary: if we have a
non-interactive shell, we will open that file descriptor if we can and
keep it around permanently (that's why the initial patch to allow
setting -m non-interatively was so simple), so obviously it's not
strictly necessary to close it when a shell isn't interactive / doesn't
have job control.

What I think is necessary is getting rid of "shout", the FILE opened to
the terminal, which is strictly for interactive use only and hence
inappropriate in a subshell (we don't want the subshell trying to do
line editing, etc.).  So it's possible the following patch makes things
work.  (The other chunk is because we allow "jobs" to work in a subshell
so you can pipe its output---if you "set -m" you're effectively making
the shell the output for "jobs" twice.)

Again, this passed a trivial smoke test.  From the non-interactive case
I think keeping SHTTY around is benign, but we're heading into
more difficult territory.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.168
diff -u -r1.168 exec.c
--- Src/exec.c	11 Jul 2009 16:43:00 -0000	1.168
+++ Src/exec.c	11 Jul 2009 18:52:56 -0000
@@ -931,11 +931,7 @@
     zsh_subshell++;
     if ((flags & ESUB_REVERTPGRP) && getpid() == mypgrp)
 	release_pgrp();
-    if (SHTTY != -1) {
-	shout = NULL;
-	zclose(SHTTY);
-	SHTTY = -1;
-    }
+    shout = NULL;
     if (isset(MONITOR)) {
 	signal_default(SIGTTOU);
 	signal_default(SIGTTIN);
Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.69
diff -u -r1.69 jobs.c
--- Src/jobs.c	10 Jul 2009 11:08:48 -0000	1.69
+++ Src/jobs.c	11 Jul 2009 18:52:56 -0000
@@ -1307,7 +1307,8 @@
 
     if (monitor && oldmaxjob) {
 	int sz = oldmaxjob * sizeof(struct job);
-	DPUTS(oldjobtab != NULL, "BUG: saving job table twice\n");
+	if (oldjobtab)
+	    free(oldjobtab);
 	oldjobtab = (struct job *)zalloc(sz);
 	memcpy(oldjobtab, jobtab, sz);
 
 
-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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