From: Timo Sirainen Date: Wed, 10 Feb 2016 17:30:42 +0000 (+0200) Subject: lib: Ignore ENOSYS errors from madvise() calls. X-Git-Tag: 2.2.22.rc1~170 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4ff6d11dc314dd2c88630f34850a6850b94e7095;p=thirdparty%2Fdovecot%2Fcore.git lib: Ignore ENOSYS errors from madvise() calls. 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. --- diff --git a/src/lib/mmap-util.c b/src/lib/mmap-util.c index 6215b13237..87807d8e83 100644 --- a/src/lib/mmap-util.c +++ b/src/lib/mmap-util.c @@ -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) { diff --git a/src/lib/mmap-util.h b/src/lib/mmap-util.h index aab2197f21..0f4184e70d 100644 --- a/src/lib/mmap-util.h +++ b/src/lib/mmap-util.h @@ -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