diff options
author | Bill Nottingham <notting@redhat.com> | 2001-02-22 04:33:18 +0000 |
---|---|---|
committer | Bill Nottingham <notting@redhat.com> | 2001-02-22 04:33:18 +0000 |
commit | 87aef170444022cdcc901be0627c9a92b773af64 (patch) | |
tree | 5820fdd12a8547cb613bd3ab8d04565fec63ccad /src/process.c | |
parent | 8ec94af1056cc65fe4cec54199521da5dbd0a522 (diff) | |
download | initscripts-87aef170444022cdcc901be0627c9a92b773af64.tar initscripts-87aef170444022cdcc901be0627c9a92b773af64.tar.gz initscripts-87aef170444022cdcc901be0627c9a92b773af64.tar.bz2 initscripts-87aef170444022cdcc901be0627c9a92b773af64.tar.xz initscripts-87aef170444022cdcc901be0627c9a92b773af64.zip |
close extra file descriptors before exec()ing commands in initlog
Diffstat (limited to 'src/process.c')
-rw-r--r-- | src/process.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/process.c b/src/process.c index b320051f..ce0d459d 100644 --- a/src/process.c +++ b/src/process.c @@ -71,6 +71,8 @@ int forkCommand(char **args, int *outfd, int *errfd, int *cmdfd, int quiet) { return pid; } else { /* kid */ + int sc_open_max; + if (outfd) { if ( (dup2(fdout,1)==-1) ) { perror("dup2"); @@ -107,6 +109,16 @@ int forkCommand(char **args, int *outfd, int *errfd, int *cmdfd, int quiet) { close(*errfd); if (cmdfd) close(*cmdfd); + + /* close up extra fds, and hope this doesn't break anything */ + sc_open_max = sysconf(_SC_OPEN_MAX); + if(sc_open_max > 1) { + int fd; + for(fd = 3; fd < sc_open_max; fd++) { + close(fd); + } + } + execvp(args[0],args); perror("execvp"); exit(-1); |