Don't try to call posix_fadvise() unless <fcntl.h> supplies a declaration
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Jun 2006 18:30:21 +0000 (18:30 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Jun 2006 18:30:21 +0000 (18:30 +0000)
for it.  Hopefully will fix core dump evidenced by some buildfarm members
since fadvise patch went in.  The actual definition of the function is not
ABI-compatible with compiler's default assumption in the absence of any
declaration, so it's clearly unsafe to try to call it without seeing a
declaration.

configure
configure.in
src/backend/access/transam/xlog.c
src/include/pg_config.h.in

index f7947ebe72e51907b695e3a9c29d0e186bb55a98..5ef6be0cd16a5b0d328eeeb847ce08319850bacb 100755 (executable)
--- a/configure
+++ b/configure
@@ -13917,6 +13917,79 @@ _ACEOF
 fi
 
 
+echo "$as_me:$LINENO: checking whether posix_fadvise is declared" >&5
+echo $ECHO_N "checking whether posix_fadvise is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_posix_fadvise+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <fcntl.h>
+
+int
+main ()
+{
+#ifndef posix_fadvise
+  char *p = (char *) posix_fadvise;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_have_decl_posix_fadvise=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_posix_fadvise=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_posix_fadvise" >&5
+echo "${ECHO_T}$ac_cv_have_decl_posix_fadvise" >&6
+if test $ac_cv_have_decl_posix_fadvise = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_POSIX_FADVISE 1
+_ACEOF
+
+
+else
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_POSIX_FADVISE 0
+_ACEOF
+
+
+fi
+
+
 
 HAVE_IPV6=no
 echo "$as_me:$LINENO: checking for struct sockaddr_in6" >&5
index 32d2f9d0a9f3be625e14bfccdea98382a95fe6a8..9b1f3acee571a3bd1847038635d6a4a6a11e82c2 100644 (file)
@@ -864,6 +864,7 @@ PGAC_FUNC_GETTIMEOFDAY_1ARG
 AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getpeereid memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs])
 
 AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
+AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
 
 HAVE_IPV6=no
 AC_CHECK_TYPE([struct sockaddr_in6],
index 0535ee677921f9eeefa20e4f155b149fff239793..dbfccfb2ea7ddc37ff7f6a84afa97962bdf6f5ef 100644 (file)
@@ -2147,11 +2147,13 @@ XLogFileClose(void)
 {
        Assert(openLogFile >= 0);
 
-#ifdef POSIX_FADV_DONTNEED
+#if defined(HAVE_DECL_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
        /*
-        * WAL caches will not be accessed in the future, so we advise OS to
-        * free them. But we will not do so if WAL archiving is active,
-        * because archivers might use the caches to read the WAL segment.
+        * WAL segment files will not be re-read in normal operation, so we advise
+        * OS to release any cached pages.  But do not do so if WAL archiving is
+        * active, because archiver process could use the cache to read the WAL
+        * segment.
+        *
         * While O_DIRECT works for O_SYNC, posix_fadvise() works for fsync()
         * and O_SYNC, and some platforms only have posix_fadvise().
         */
index 5ccfbfefd28f5b72e75d3a7f1ba43d1cb55773be..82ccde63c1c2f7b8cf45c493415be6200376b5ae 100644 (file)
    don't. */
 #undef HAVE_DECL_F_FULLFSYNC
 
+/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
+   don't. */
+#undef HAVE_DECL_POSIX_FADVISE
+
 /* Define to 1 if you have the declaration of `snprintf', and to 0 if you
    don't. */
 #undef HAVE_DECL_SNPRINTF