- instead of just "100 should be large enough", use sysconf() to grab
number of max open files and do them all. If sysconf() fails,
use 1024 as "should be enough for everybody"
int flag;
int fdno;
int xx;
+ int open_max;
pipes[0] = pipes[1] = 0;
/* make stdin inaccessible */
xx = dup2(pipes[0], STDIN_FILENO);
xx = close(pipes[0]);
- /* XXX Force FD_CLOEXEC on 1st 100 inherited fdno's. */
- for (fdno = 3; fdno < 100; fdno++) {
+ /* XXX Force FD_CLOEXEC on all inherited fdno's. */
+ open_max = sysconf(_SC_OPEN_MAX);
+ if (open_max == -1) {
+ open_max = 1024;
+ }
+ for (fdno = 3; fdno < open_max; fdno++) {
flag = fcntl(fdno, F_GETFD);
if (flag == -1 || (flag & FD_CLOEXEC))
continue;