Просмотр исходного кода

add a segfault handler to MMap to show the Cache-Limit message, which
can be deactivated with MMap::SegfaultHandler=false (Closes: 535218)

David Kalnischkies лет назад: 17
Родитель
Сommit
13eb93fcb6
2 измененных файлов с 26 добавлено и 0 удалено
  1. 24 0
      apt-pkg/contrib/mmap.cc
  2. 2 0
      debian/changelog

+ 24 - 0
apt-pkg/contrib/mmap.cc

@@ -19,6 +19,7 @@
 #define _BSD_SOURCE
 #define _BSD_SOURCE
 #include <apt-pkg/mmap.h>
 #include <apt-pkg/mmap.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
 
 
 #include <apti18n.h>
 #include <apti18n.h>
 
 
@@ -26,6 +27,8 @@
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include <signal.h>
 
 
 #include <cstring>
 #include <cstring>
    									/*}}}*/
    									/*}}}*/
@@ -136,6 +139,20 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
+// DynamicMMapSegfaultHandler						/*{{{*/
+// ---------------------------------------------------------------------
+/* In theory, the mmap should never segfault because we check the available
+   size of our mmap before we use it, but there are a few reports out there
+   which state that the mmap segfaults without further notice. So this handler
+   will take care of all these segfaults which should never happen... */
+void DynamicMMapSegfaultHandler(int)
+{
+   _error->Error(_("Dynamic MMap segfaults, most likely because it ran out of room. "
+		   "Please increase the size of APT::Cache-Limit. (man 5 apt.conf)"));
+   _error->DumpErrors();
+   exit(EXIT_FAILURE);
+}
+									/*}}}*/
 // DynamicMMap::DynamicMMap - Constructor				/*{{{*/
 // DynamicMMap::DynamicMMap - Constructor				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
@@ -170,6 +187,13 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long WorkSpace) :
    if (_error->PendingError() == true)
    if (_error->PendingError() == true)
       return;
       return;
 
 
+   if (_config->FindB("MMap::SegfaultHandler",true) == true)
+   {
+      struct sigaction sa;
+      sa.sa_handler = DynamicMMapSegfaultHandler;
+      sigaction(SIGSEGV, &sa, NULL);
+   }
+
 #ifdef _POSIX_MAPPED_FILES
 #ifdef _POSIX_MAPPED_FILES
    // use anonymous mmap() to get the memory
    // use anonymous mmap() to get the memory
    Base = (unsigned char*) mmap(0, WorkSpace, PROT_READ|PROT_WRITE,
    Base = (unsigned char*) mmap(0, WorkSpace, PROT_READ|PROT_WRITE,

+ 2 - 0
debian/changelog

@@ -36,6 +36,8 @@ apt (0.7.22) UNRELEASED; urgency=low
   * versions with a pin of -1 shouldn't be a candidate (Closes: #355237)
   * versions with a pin of -1 shouldn't be a candidate (Closes: #355237)
   * prefer mmap as memory allocator in MMap instead of a static char
   * prefer mmap as memory allocator in MMap instead of a static char
     array which can (at least in theory) grow dynamic
     array which can (at least in theory) grow dynamic
+  * add a segfault handler to MMap to show the Cache-Limit message, which
+    can be deactivated with MMap::SegfaultHandler=false (Closes: 535218)
 
 
   [ Michael Vogt ]
   [ Michael Vogt ]
   * honor the dpkg hold state in new Marker hooks (closes: #64141)
   * honor the dpkg hold state in new Marker hooks (closes: #64141)