diff options
author | Guillem Jover <guillem@debian.org> | 2010-05-26 02:37:42 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2010-05-26 02:51:28 +0200 |
commit | e844672595246c81f4a8e45ca842dc6aa3a4dbc8 (patch) | |
tree | ffbef18e22bd0241b148fd9bad87c8264ed96180 | |
parent | e1ce8e5e0027333a0f3071b9d8bd81b53cbb1011 (diff) | |
download | dpkg-e844672595246c81f4a8e45ca842dc6aa3a4dbc8.tar.gz |
build: Only use mmap in parser if explicitly requested
The current mmap code is not reliable, as it does not handle SIGBUS,
which can happen on I/O errors (among others). Switch the code to
check for USE_MMAP instead of HAVE_MMAP so that it can be explicitly
enabled on build, to produce consistent results by making sure it does
not get reactivated accidentally. Disable it by default due to the
above, in addition to not having been used by released tarballs since
1.14.15.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | lib/dpkg/parse.c | 6 | ||||
-rw-r--r-- | m4/dpkg-funcs.m4 | 16 |
3 files changed, 21 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 6e8c6b9bb..bf9a7b4ef 100644 --- a/configure.ac +++ b/configure.ac @@ -127,6 +127,8 @@ DPKG_CHECK_COMPAT_FUNCS([getopt getopt_long obstack_free \ AC_CHECK_FUNCS([strtoul isascii bcopy memcpy lchown setsid getdtablesize \ posix_fadvise]) +DPKG_MMAP + AC_DEFINE(LIBDPKG_VOLATILE_API, 1, [Acknowledge the volatility of the API.]) DPKG_COMPILER_WARNINGS DPKG_COMPILER_OPTIMISATIONS diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c index c439a7f57..b8ee07a7c 100644 --- a/lib/dpkg/parse.c +++ b/lib/dpkg/parse.c @@ -23,7 +23,7 @@ #include <sys/types.h> #include <sys/stat.h> -#ifdef HAVE_MMAP +#ifdef USE_MMAP #include <sys/mman.h> #endif @@ -121,7 +121,7 @@ int parsedb(const char *filename, enum parsedbflags flags, ohshite(_("can't stat package info file `%.255s'"),filename); if (st.st_size > 0) { -#ifdef HAVE_MMAP +#ifdef USE_MMAP dataptr = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (dataptr == MAP_FAILED) ohshite(_("can't mmap package info file `%.255s'"),filename); @@ -386,7 +386,7 @@ int parsedb(const char *filename, enum parsedbflags flags, ps.lno++; } if (data != NULL) { -#ifdef HAVE_MMAP +#ifdef USE_MMAP munmap(data, st.st_size); #else free(data); diff --git a/m4/dpkg-funcs.m4 b/m4/dpkg-funcs.m4 index 188fa6bd8..3f0cf5261 100644 --- a/m4/dpkg-funcs.m4 +++ b/m4/dpkg-funcs.m4 @@ -68,6 +68,22 @@ AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"], AM_CONDITIONAL(HAVE_C99_SNPRINTF, [test "x$dpkg_cv_c99_snprintf" = "xyes"]) ])# DPKG_FUNC_C99_SNPRINTF +# DPKG_MMAP +# --------- +# Define USE_MMAP if mmap() is available and it was requested +AC_DEFUN([DPKG_MMAP], +[ + AC_ARG_ENABLE([mmap], + AS_HELP_STRING([--enable-mmap], + [enable usage of unrealiable mmap if available]), + [ + AC_CHECK_FUNCS([mmap]) + AC_DEFINE(USE_MMAP, 1, [Use unreliable mmap support]) + ], + [] + ) +]) + # DPKG_FUNC_ASYNC_SYNC # -------------------- # Define HAVE_ASYNC_SYNC if sync() is asynchronous |