Browse code

check for madvise()

aCaB authored on 2009/10/10 23:37:55
Showing 4 changed files
... ...
@@ -250,6 +250,9 @@
250 250
 /* Define to 1 if you have the <mach-o/dyld.h> header file. */
251 251
 #undef HAVE_MACH_O_DYLD_H
252 252
 
253
+/* Define to 1 if you have the `madvise' function. */
254
+#undef HAVE_MADVISE
255
+
253 256
 /* Define to 1 if you have the `mallinfo' function. */
254 257
 #undef HAVE_MALLINFO
255 258
 
... ...
@@ -13508,7 +13508,7 @@ if test "$ac_res" != no; then :
13508 13508
 fi
13509 13509
 
13510 13510
 
13511
-for ac_func in poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo
13511
+for ac_func in poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo madvise
13512 13512
 do :
13513 13513
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
13514 13514
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
... ...
@@ -432,7 +432,7 @@ fi
432 432
 AC_CHECK_LIB([socket], [bind], [LIBS="$LIBS -lsocket"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsocket"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsocket"; CLAMD_LIBS="$CLAMD_LIBS -lsocket"])
433 433
 AC_SEARCH_LIBS([gethostent],[nsl], [(LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lnsl"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lnsl"; CLAMD_LIBS="$CLAMD_LIBS -lnsl")])
434 434
 
435
-AC_CHECK_FUNCS([poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo])
435
+AC_CHECK_FUNCS([poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo madvise])
436 436
 AC_FUNC_FSEEKO
437 437
 
438 438
 dnl Check if anon maps are available, check if we can determine the page size
... ...
@@ -57,7 +57,7 @@
57 57
 #define UNPAGE_THRSHLD_HI 8*1024*1024
58 58
 #define READAHEAD_PAGES 8
59 59
 
60
-#ifdef C_LINUX
60
+#if defined(HAVE_MMAP) && defined(C_LINUX)
61 61
 /*
62 62
    WORKAROUND
63 63
    Relieve some stress on mmap_sem.
... ...
@@ -72,6 +72,10 @@ pthread_mutex_t fmap_mutex = PTHREAD_MUTEX_INITIALIZER;
72 72
 #define fmap_unlock
73 73
 #endif
74 74
 
75
+#ifndef MADV_DONTFORK
76
+#define MADV_DONTFORK 0
77
+#endif
78
+
75 79
 #define fmap_bitmap (&m->placeholder_for_bitmap)
76 80
 
77 81
 /* pread proto here in order to avoid the use of XOPEN and BSD_SOURCE
... ...
@@ -123,11 +127,13 @@ fmap_t *fmap(int fd, off_t offset, size_t len) {
123 123
 	m = NULL;
124 124
     } else {
125 125
 	dumb = 0;
126
+#if HAVE_MADVISE
126 127
 	madvise(m, mapsz, MADV_RANDOM|MADV_DONTFORK);
128
+#endif /* madvise */
127 129
     }
128
-#else
130
+#else /* ! HAVE_MMAP */
129 131
     m = (fmap_t *)cli_malloc(mapsz);
130
-#endif
132
+#endif /* HAVE_MMAP */
131 133
     if(!m) {
132 134
 	cli_warnmsg("fmap: map allocation failed\n");
133 135
 	fmap_unlock;