Bläddra i källkod

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.
Guillem Jover 16 år sedan
förälder
incheckning
e844672595
3 ändrade filer med 21 tillägg och 3 borttagningar
  1. 2 0
      configure.ac
  2. 3 3
      lib/dpkg/parse.c
  3. 16 0
      m4/dpkg-funcs.m4

+ 2 - 0
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

+ 3 - 3
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);

+ 16 - 0
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