]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
fix regression that APT::Keep-Fds is not honored (closes: #730490)
[apt.git] / apt-pkg / contrib / fileutl.cc
index 0261119ba120001b2f233b343a9f40503f4eb5f4..3a6bdfe2ec431b6872ef3a45cb2c5e41c130e2b1 100644 (file)
@@ -760,12 +760,42 @@ bool WaitFd(int Fd,bool write,unsigned long timeout)
    return true;
 }
                                                                        /*}}}*/
+// MergeKeepFdsFromConfiguration - Merge APT::Keep-Fds configuration   /*{{{*/
+// ---------------------------------------------------------------------
+/* This is used to merge the APT::Keep-Fds with the provided KeepFDs
+ * set.
+ */
+void MergeKeepFdsFromConfiguration(std::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);
+        }
+      }
+}
+                                                                       /*}}}*/
 // ExecFork - Magical fork that sanitizes the context before execing   /*{{{*/
 // ---------------------------------------------------------------------
 /* 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()
+{
+      set<int> KeepFDs;
+      // we need to merge the Keep-Fds as external tools like 
+      // debconf-apt-progress use it
+      MergeKeepFdsFromConfiguration(KeepFDs);
+      return ExecFork(KeepFDs);
+}
+
+pid_t ExecFork(std::set<int> KeepFDs)
 {
    // Fork off the process
    pid_t Process = fork();
@@ -786,22 +816,8 @@ pid_t ExecFork()
       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++)
+      for (int K = 3; K != sysconf(_SC_OPEN_MAX); K++)
       {
         if(KeepFDs.find(K) == KeepFDs.end())
            fcntl(K,F_SETFD,FD_CLOEXEC);