aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2001-03-30 17:24:51 +0000
committerBill Nottingham <notting@redhat.com>2001-03-30 17:24:51 +0000
commita0c75baff9467b5422697aee749d06067aa76902 (patch)
treed31ef92c69ce55a48f4132738af72989a126237c /src
parente2446c6407f9f339f89cd2968577d2aa7bdb943c (diff)
downloadinitscripts-a0c75baff9467b5422697aee749d06067aa76902.tar
initscripts-a0c75baff9467b5422697aee749d06067aa76902.tar.gz
initscripts-a0c75baff9467b5422697aee749d06067aa76902.tar.bz2
initscripts-a0c75baff9467b5422697aee749d06067aa76902.tar.xz
initscripts-a0c75baff9467b5422697aee749d06067aa76902.zip
close extra file descriptors before exec()ing commands in initlog
Diffstat (limited to 'src')
-rw-r--r--src/process.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/process.c b/src/process.c
index b320051f..4ff805ef 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,17 @@ 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++) {
+ if (!(cmdfd && fd == CMD_FD))
+ close(fd);
+ }
+ }
+
execvp(args[0],args);
perror("execvp");
exit(-1);