X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b81af2c2bb8a4b41b8adbb1c351fbd0964542558..dde60c5696f6779ea48febdac315083fb50e3075:/apt-pkg/contrib/fileutl.cc?ds=sidebyside diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 0ce0c9b9d..9e13b4f60 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -14,15 +14,16 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/fileutl.h" -#endif #include #include #include +#include #include +#include +#include + #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include /*}}}*/ using namespace std; @@ -306,7 +308,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 +328,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;