summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-11-23 09:13:30 +0100
committerMichael Vogt <mvo@debian.org>2013-11-23 09:13:30 +0100
commit7d2428e03c1fdae79488b9ecd53cc5257b2a0c13 (patch)
tree81209b60212c997452fd74cf184b8ca5445e8bc0 /apt-pkg/contrib/fileutl.cc
parentf62f17b489405432a3125e51471d8a00e78c5170 (diff)
parent61f954bff040809e7ab57b3adec2fe95339ffb94 (diff)
Merge branch 'debian/sid' into ubuntu/master
Conflicts: debian/changelog
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc36
1 files changed, 21 insertions, 15 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 0261119ba..d2be276c7 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -767,6 +767,26 @@ bool WaitFd(int Fd,bool write,unsigned long timeout)
otherwise acts like normal fork. */
pid_t ExecFork()
{
+ set<int> KeepFDs;
+
+ // FIXME: remove looking at APT::Keep-Fds eventually, its a hack
+ 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);
+ }
+ }
+ return ExecFork(KeepFDs);
+}
+
+pid_t ExecFork(std::set<int> KeepFDs)
+{
// Fork off the process
pid_t Process = fork();
if (Process < 0)
@@ -786,22 +806,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);