Browse Source

Use sysconf(_SC_ARG_MAX) to find the size of Dpkg::MaxArgBytes

Instead of hardcoding Dpkg::MaxArgBytes find out about it using
the sysconf(_SC_ARG_MAX) call.
Michael Vogt 11 years ago
parent
commit
a3cada6abc
1 changed files with 21 additions and 2 deletions
  1. 21 2
      apt-pkg/deb/dpkgpm.cc

+ 21 - 2
apt-pkg/deb/dpkgpm.cc

@@ -55,6 +55,18 @@
 
 
 using namespace std;
 using namespace std;
 
 
+APT_PURE static unsigned int
+EnvironmentSize()
+{
+  unsigned int size = 0;
+  char **envp = environ;
+
+  while (*envp != NULL)
+    size += strlen (*envp++) + 1;
+
+  return size;
+}
+
 class pkgDPkgPMPrivate 
 class pkgDPkgPMPrivate 
 {
 {
 public:
 public:
@@ -1236,8 +1248,15 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
    fd_set rfds;
    fd_set rfds;
    struct timespec tv;
    struct timespec tv;
 
 
-   unsigned int const MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024);
-   unsigned int const MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024);
+   // FIXME: do we really need this limit when we have MaxArgBytes?
+   unsigned int const MaxArgs = _config->FindI("Dpkg::MaxArgs",32*1024);
+
+   // try to figure out the max environment size
+   unsigned int OSArgMax = sysconf(_SC_ARG_MAX);
+   if(OSArgMax < 0)
+      OSArgMax = 32*1024;
+   OSArgMax -= EnvironmentSize() - 2*1024;
+   unsigned int const MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes", OSArgMax);
    bool const NoTriggers = _config->FindB("DPkg::NoTriggers", false);
    bool const NoTriggers = _config->FindB("DPkg::NoTriggers", false);
 
 
    if (RunScripts("DPkg::Pre-Invoke") == false)
    if (RunScripts("DPkg::Pre-Invoke") == false)