diff --git a/src/lib/bpipe.c b/src/lib/bpipe.c index d808a31af94..1158ef77d29 100644 --- a/src/lib/bpipe.c +++ b/src/lib/bpipe.c @@ -127,9 +127,23 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode) } /* Note, the close log cause problems, see bug #1536 */ /* closelog(); close syslog if open */ - for (i=3; i<=32; i++) { /* close any open file descriptors */ + +#if defined(HAVE_FCNTL_F_CLOSEM) + /* + * fcntl(fd, F_CLOSEM) needs the lowest filedescriptor to close. + */ + fcntl(3, F_CLOSEM); +#elif defined(HAVE_CLOSEFROM) + /* + * closefrom needs the lowest filedescriptor to close. + */ + closefrom(3); +#else + for (i = 3; i <= 32; i++) { /* close any open file descriptors */ close(i); } +#endif + execvp(bargv[0], bargv); /* call the program */ /* Convert errno into an exit code for later analysis */ for (i=0; i< num_execvp_errors; i++) { diff --git a/src/lib/daemon.c b/src/lib/daemon.c index 0ab74bf16e6..02fa6773428 100644 --- a/src/lib/daemon.c +++ b/src/lib/daemon.c @@ -70,7 +70,7 @@ daemon_start() #if defined(HAVE_FCNTL_F_CLOSEM) /* - * fcntl(fd, F_CLOSEM) needs the minimum filedescriptor + * fcntl(fd, F_CLOSEM) needs the lowest filedescriptor * to close. the current code sets the last one to keep * open. So increment it with 1 and use that as argument. */ @@ -78,7 +78,7 @@ daemon_start() fcntl(low_fd, F_CLOSEM); #elif defined(HAVE_CLOSEFROM) /* - * closefrom needs the minimum filedescriptor to close. + * closefrom needs the lowest filedescriptor to close. * the current code sets the last one to keep open. * So increment it with 1 and use that as argument. */