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

Re: non-interactive set -m



On Sat, 11 Jul 2009 19:57:02 +0100
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> 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.

We should make sure it's closed on an exec, however.  This maybe what
the previous code was trying to do.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.169
diff -u -r1.169 exec.c
--- Src/exec.c	11 Jul 2009 19:06:52 -0000	1.169
+++ Src/exec.c	12 Jul 2009 14:38:36 -0000
@@ -595,6 +595,12 @@
      * here, which should be visible to external processes.
      */
     closem(FDT_XTRACE);
+#ifndef FD_CLOEXEC
+    if (SHTTY != -1) {
+	close(SHTTY);
+	SHTTY = -1;
+    }
+#endif
     child_unblock();
     if ((int) strlen(arg0) >= PATH_MAX) {
 	zerr("command too long: %s", arg0);
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.105
diff -u -r1.105 init.c
--- Src/init.c	11 Jul 2009 16:43:00 -0000	1.105
+++ Src/init.c	12 Jul 2009 14:38:36 -0000
@@ -480,8 +480,16 @@
     if (SHTTY == -1) {
 	zsfree(ttystrname);
 	ttystrname = ztrdup("");
-    } else if (!ttystrname) {
-	ttystrname = ztrdup("/dev/tty");
+    } else {
+#ifdef FD_CLOEXEC
+	long fdflags = fcntl(SHTTY, F_GETFD, 0);
+	if (fdflags != (long)-1) {
+	    fdflags |= FD_CLOEXEC;
+	    fcntl(SHTTY, F_SETFD, fdflags);
+	}
+#endif
+	if (!ttystrname)
+	    ttystrname = ztrdup("/dev/tty");
     }
 
     /* We will only use zle if shell is interactive, *

-- 
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