]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Ignore ENOSYS errors from madvise() calls.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 10 Feb 2016 17:30:42 +0000 (19:30 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 11 Feb 2016 11:35:01 +0000 (13:35 +0200)
For example Raspberry Pi kernels have removed this. We'll wrap all the
madvise() calls with my_madvise() to avoid extra checks all over the place.

src/lib/mmap-util.c
src/lib/mmap-util.h

index 6215b132376dc3ce163cb7aa31fc3ae70facd8dd..87807d8e83ba2e32d49d5bba2411a2b5e4634f45 100644 (file)
@@ -37,13 +37,18 @@ void *mmap_rw_file(int fd, size_t *length)
        return mmap_file(fd, length, PROT_READ | PROT_WRITE);
 }
 
-#ifndef HAVE_MADVISE
+#undef madvise
 int my_madvise(void *start ATTR_UNUSED, size_t length ATTR_UNUSED,
               int advice ATTR_UNUSED)
 {
+#ifdef HAVE_MADVISE
+       /* Ignore ENOSYS errors, which happen if the kernel hasn't implemented
+          the syscall even if libc has. */
+       if (madvise(start, length, advice) < 0 && errno != ENOSYS)
+               return -1;
+#endif
        return 0;
 }
-#endif
 
 size_t mmap_get_page_size(void)
 {
index aab2197f21009c1db6d1226bc4f49373799d6509..0f4184e70db22ec62c5ef2aab6ea2a7801880274 100644 (file)
@@ -14,9 +14,9 @@
 #  define MREMAP_MAYMOVE 1
 #endif
 
-#ifndef HAVE_MADVISE
-#  define madvise my_madvise
+#define madvise my_madvise
 int my_madvise(void *start, size_t length, int advice);
+#ifndef HAVE_MADVISE
 #  ifndef MADV_NORMAL
 #    define MADV_NORMAL 0
 #    define MADV_RANDOM 0