Aaron Sethman <andro...@ratbox.org> said: > On Mon, 10 Feb 2003, Alberto Gonzalez Iniesta wrote: > > > > > Hi, > > > > Again, I'm no C hacker, but I think this should be better: > > > > for(x = 3; x < 100; x++) > > > > Since the first 3 fds (stdin, stdout and stderr) should be kept open. > > > Wasn't sure if stdin, stdout and stderr needed to be left open or not in > this case. Obviously this is an easy fix :)
Actually, I was just thinking what a pain to have to reimplement system() just to close a few fds. There must be a better way, and as it turns out, there is: /* Set a file descriptor to not be passed across execs */ void set_cloexec (int fd) { if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0) msg (M_ERR, "Set file descriptor to FD_CLOEXEC failed"); } Just set the FD_CLOEXEC flag on the fd and it won't be passed across the exec that runs the shell. I already wrote the patch and it's in the CVS. James