X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/e8044cfac86e388d2b894d497be256b82bda52d6..a44aeb52f0476ed56feff82b1cfd2fa84e7a1223:/apt-pkg/contrib/fileutl.cc diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 0ce0c9b9d..d19a92e62 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -14,15 +14,14 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/fileutl.h" -#endif #include #include #include +#include #include +#include #include #include #include @@ -32,6 +31,7 @@ #include #include #include +#include /*}}}*/ using namespace std; @@ -306,7 +306,7 @@ bool WaitFd(int Fd,bool write,unsigned long timeout) /* This is used if you want to cleanse the environment for the forked child, it fixes up the important signals and nukes all of the fds, otherwise acts like normal fork. */ -pid_t ExecFork(int dontCloseThisFd) +pid_t ExecFork() { // Fork off the process pid_t Process = fork(); @@ -326,11 +326,27 @@ pid_t ExecFork(int dontCloseThisFd) signal(SIGWINCH,SIG_DFL); signal(SIGCONT,SIG_DFL); signal(SIGTSTP,SIG_DFL); - + + set KeepFDs; + Configuration::Item const *Opts = _config->Tree("APT::Keep-Fds"); + if (Opts != 0 && Opts->Child != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + int fd = atoi(Opts->Value.c_str()); + KeepFDs.insert(fd); + } + } + // Close all of our FDs - just in case for (int K = 3; K != 40; K++) - if(K != dontCloseThisFd) + { + if(KeepFDs.find(K) == KeepFDs.end()) fcntl(K,F_SETFD,FD_CLOEXEC); + } } return Process;