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

Re: bug with eval, proc-subst and pipes



On Fri, 19 Jul 2013 21:58:53 +0100
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> and fd 13 by closedumps() (the missing link to compinit?).

That's distinctly suspicious, if 13 was opened for the process
substitution.

Does the following fix it, or is there yet more?

If it does we still have an error for older systems, but I suspect
FD_CLOEXEC (and O_CLOEXEC) are widely enough supported that may be more
a theoretical then an actual problem.

diff --git a/Src/exec.c b/Src/exec.c
index d462d97..f9efb3a 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -448,7 +448,9 @@ zexecve(char *pth, char **argv, char **newenvp)
     else
 	sprintf(buf + 2, "%s/%s", pwd, pth);
     zputenv(buf);
+#ifndef FD_CLOEXEC
     closedumps();
+#endif
 
     if (newenvp == NULL)
 	    newenvp = environ;
diff --git a/Src/parse.c b/Src/parse.c
index 753080d..b670925 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -3171,6 +3171,9 @@ load_dump_file(char *dump, struct stat *sbuf, int other, int len)
     d->dev = sbuf->st_dev;
     d->ino = sbuf->st_ino;
     d->fd = fd;
+#ifdef FD_CLOEXEC
+    fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
     d->map = addr + (other ? (len - off) / sizeof(wordcode) : 0);
     d->addr = addr;
     d->len = len;
@@ -3439,6 +3442,7 @@ decrdumpcount(FuncDump f)
     }
 }
 
+#ifndef FD_CLOEXEC
 /**/
 mod_export void
 closedumps(void)
@@ -3448,6 +3452,7 @@ closedumps(void)
     for (p = dumps; p; p = p->next)
 	zclose(p->fd);
 }
+#endif
 
 #else
 
@@ -3461,11 +3466,13 @@ decrdumpcount(FuncDump f)
 {
 }
 
+#ifndef FD_CLOEXEC
 /**/
 mod_export void
 closedumps(void)
 {
 }
+#endif
 
 #endif
 
-- 
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