From 870a2b6d683e58c0584bbd3614a76cf25a055928 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 25 May 2015 16:45:05 +0200 Subject: ExecFork: Use /proc/self/fd to determine which files to close This significantly reduces the number of files that have to be closed and seems to be faster, despite the additional reads. On systems where /proc/self/fd is not available, we fallback to the old code that closes all file descriptors >= 3. Closes: #764204 --- apt-pkg/contrib/fileutl.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1e6d96fe9..6e34f5d28 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -778,12 +778,26 @@ pid_t ExecFork(std::set KeepFDs) signal(SIGCONT,SIG_DFL); signal(SIGTSTP,SIG_DFL); - long ScOpenMax = sysconf(_SC_OPEN_MAX); - // Close all of our FDs - just in case - for (int K = 3; K != ScOpenMax; K++) + DIR *dir = opendir("/proc/self/fd"); + if (dir != NULL) { - if(KeepFDs.find(K) == KeepFDs.end()) - fcntl(K,F_SETFD,FD_CLOEXEC); + struct dirent *ent; + while ((ent = readdir(dir))) + { + int fd = atoi(ent->d_name); + // If fd > 0, it was a fd number and not . or .. + if (fd >= 3 && KeepFDs.find(fd) == KeepFDs.end()) + fcntl(fd,F_SETFD,FD_CLOEXEC); + } + closedir(dir); + } else { + long ScOpenMax = sysconf(_SC_OPEN_MAX); + // Close all of our FDs - just in case + for (int K = 3; K != ScOpenMax; K++) + { + if(KeepFDs.find(K) == KeepFDs.end()) + fcntl(K,F_SETFD,FD_CLOEXEC); + } } } -- cgit v1.2.3 From 3b216cf6b6e082b7de4dfece65601a96d269d529 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 24 Jul 2015 17:34:30 +0200 Subject: updated for the gcc5 transition --- apt-pkg/contrib/configuration.h | 1 + apt-pkg/contrib/macros.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index c256139f4..fde9cf851 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -33,6 +33,7 @@ #include #include #include +#include #ifndef APT_8_CLEANER_HEADERS using std::string; diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index 2d6448e5e..b9ec161af 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -138,7 +138,7 @@ // Non-ABI-Breaks should only increase RELEASE number. // See also buildlib/libversion.mak #define APT_PKG_MAJOR 4 -#define APT_PKG_MINOR 12 +#define APT_PKG_MINOR 16 #define APT_PKG_RELEASE 0 #endif -- cgit v1.2.3 From 91cdf3199cb8487eb38a14e2d1d5195ebe51e802 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 25 Jul 2015 10:52:42 +0200 Subject: bump next-abi check above gcc5-abi bump Some of the 'simpler' abi changes are included in /sid already guarded behind #if's and now that we dumped the ABI fpr gcc5 they trigger. It would probably not hurt to have them trigger and it is an abi break anyway, but there isn't much point to it and it would be really annoying if one of them turns out to be a problem as these changes aren't as well tested as the 'old' abi. It is slightly incorrect to check for abi >= 17 as /experimental with this (and other changes) is abi = 15 currently, but writing the correct check would be just too insane for this dead ends branch. Final /experimental is probably better of increasing APT_PKG_MAJOR anyhow. --- apt-pkg/contrib/configuration.cc | 2 +- apt-pkg/contrib/configuration.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 00f6ad0f9..e0671bcc0 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -253,7 +253,7 @@ string Configuration::FindDir(const char *Name,const char *Default) const // Configuration::FindVector - Find a vector of values /*{{{*/ // --------------------------------------------------------------------- /* Returns a vector of config values under the given item */ -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13) +#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 17) vector Configuration::FindVector(const char *Name) const { return FindVector(Name, ""); } #endif vector Configuration::FindVector(const char *Name, std::string const &Default) const diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index fde9cf851..5273b29bb 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -85,7 +85,7 @@ class Configuration * \param Default list of values separated by commas */ std::vector FindVector(const char *Name, std::string const &Default) const; std::vector FindVector(std::string const &Name, std::string const &Default) const { return FindVector(Name.c_str(), Default); }; -#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) +#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 17) std::vector FindVector(const char *Name) const { return FindVector(Name, ""); }; #else std::vector FindVector(const char *Name) const; -- cgit v1.2.3