]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
* fix missing SetExecClose() call when the status-fd is used
[apt.git] / apt-pkg / contrib / fileutl.cc
index 7c9f5c0dd5470b16520512a2e9d707778405fa5d..9e13b4f60d05ebd916b15d958e095b2f941325cc 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/fileutl.h"
-#endif 
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/sptr.h>
+#include <apt-pkg/configuration.h>
 
 #include <apti18n.h>
 
+#include <cstdlib>
+#include <cstring>
+
 #include <iostream>
 #include <unistd.h>
 #include <fcntl.h>
@@ -32,6 +33,7 @@
 #include <sys/wait.h>
 #include <signal.h>
 #include <errno.h>
+#include <set>
                                                                        /*}}}*/
 
 using namespace std;
@@ -326,10 +328,27 @@ pid_t ExecFork()
       signal(SIGWINCH,SIG_DFL);
       signal(SIGCONT,SIG_DFL);
       signal(SIGTSTP,SIG_DFL);
-      
+
+      set<int> 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++)
-        fcntl(K,F_SETFD,FD_CLOEXEC);
+      {
+        if(KeepFDs.find(K) == KeepFDs.end())
+           fcntl(K,F_SETFD,FD_CLOEXEC);
+      }
    }
    
    return Process;
@@ -355,7 +374,7 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
       if (Reap == true)
         return false;
       
-      return _error->Error(_("Waited, for %s but it wasn't there"),Name);
+      return _error->Error(_("Waited for %s but it wasn't there"),Name);
    }