summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2001-02-22 04:33:18 +0000
committerBill Nottingham <notting@redhat.com>2001-02-22 04:33:18 +0000
commit87aef170444022cdcc901be0627c9a92b773af64 (patch)
tree5820fdd12a8547cb613bd3ab8d04565fec63ccad
parent8ec94af1056cc65fe4cec54199521da5dbd0a522 (diff)
downloadinitscripts-87aef170444022cdcc901be0627c9a92b773af64.tar.gz
initscripts-87aef170444022cdcc901be0627c9a92b773af64.tar.xz
initscripts-87aef170444022cdcc901be0627c9a92b773af64.zip
close extra file descriptors before exec()ing commands in initlog
-rw-r--r--initscripts.spec5
-rw-r--r--src/process.c12
-rw-r--r--src/testd.c1
3 files changed, 17 insertions, 1 deletions
diff --git a/initscripts.spec b/initscripts.spec
index aa003796..019a7415 100644
--- a/initscripts.spec
+++ b/initscripts.spec
@@ -1,6 +1,6 @@
Summary: The inittab file and the /etc/init.d scripts.
Name: initscripts
-Version: 5.65
+Version: 5.66
Copyright: GPL
Group: System Environment/Base
Release: 1
@@ -254,6 +254,9 @@ rm -rf $RPM_BUILD_ROOT
%ghost %attr(0664,root,utmp) /var/run/utmp
%changelog
+* Wed Feb 21 Nalin Dahyabhai <nalin@redhat.com>
+- close extra file descriptors before exec()ing commands in initlog
+
* Mon Feb 19 2001 Bill Nottingham <notting@redhat.com>
- fix some substitions in init.d/functions (fixes various killproc issues)
- make sure ipv6 module alias is available if configured
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);
diff --git a/src/testd.c b/src/testd.c
index 7deb00eb..b2a5c7e6 100644
--- a/src/testd.c
+++ b/src/testd.c
@@ -1,5 +1,6 @@
#include <sys/signal.h>
#include <unistd.h>
+#include <stdlib.h>
int main() {
signal(SIGTERM, SIG_IGN);