diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2009-07-08 01:11:16 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2009-07-08 01:11:16 +0200 |
commit | 13eb93fcb6a03afd8fc05fa2b4c60046473e8507 (patch) | |
tree | 7ddbb393da97cea77eaca05cf991b514606daebf /apt-pkg/contrib | |
parent | f1c6a8ca0511c623a16bb804ed2c5b6c26c83d78 (diff) |
add a segfault handler to MMap to show the Cache-Limit message, which
can be deactivated with MMap::SegfaultHandler=false (Closes: 535218)
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/mmap.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 073bc9eb3..5f56178f4 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -19,6 +19,7 @@ #define _BSD_SOURCE #include <apt-pkg/mmap.h> #include <apt-pkg/error.h> +#include <apt-pkg/configuration.h> #include <apti18n.h> @@ -26,6 +27,8 @@ #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> +#include <stdlib.h> +#include <signal.h> #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 /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -170,6 +187,13 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long WorkSpace) : if (_error->PendingError() == true) return; + if (_config->FindB("MMap::SegfaultHandler",true) == true) + { + struct sigaction sa; + sa.sa_handler = DynamicMMapSegfaultHandler; + sigaction(SIGSEGV, &sa, NULL); + } + #ifdef _POSIX_MAPPED_FILES // use anonymous mmap() to get the memory Base = (unsigned char*) mmap(0, WorkSpace, PROT_READ|PROT_WRITE, |