make ruby bindings compile with newer ruby versions ... fix for #217
[rrdtool.git] / acinclude.m4
index d0f8c0e..5ea34f0 100644 (file)
@@ -36,9 +36,9 @@ AC_DEFUN([EX_CHECK_ALL],
              LDFLAGS=${LDFLAGS}" "`$PKGCONFIG --libs-only-other $4`
              LIBS=${LIBS}" "`$PKGCONFIG --libs-only-l $4`
             dnl remove the cached value and test again
-            unset ac_cv_lib_$1_$2
+            unset ac_cv_lib_`echo $1 | sed ['s/[^_a-zA-Z0-9]/_/g;s/^[0-9]/_/']`_$2
              AC_CHECK_LIB($1,$2,[
-                unset ac_cv_header_`echo $3 | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']`
+                unset ac_cv_header_`echo $3 | sed ['s/[^_a-zA-Z0-9]/_/g;s/^[0-9]/_/']`
                 AC_CHECK_HEADER($3,[EX_CHECK_STATE=YES],[])
             ],[])
           else
@@ -506,4 +506,87 @@ esac
   AC_MSG_RESULT([${T_MD}$1${T_ME}])
 ])
 
+dnl check 
+
+AC_DEFUN([CHECK_FOR_WORKING_MS_ASYNC], [
+AC_MSG_CHECKING([if msync with MS_ASYNC updates the files mtime])
+AC_CACHE_VAL([rd_cv_ms_async],
+[AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <utime.h>
+int main(void){
+        int fd;
+        struct stat stbuf;
+        char *addr;
+        int res;
+        char temp[] = "mmaptestXXXXXX";
+        struct utimbuf newtime;
+
+        time_t create_ts;
+        fd = mkstemp(temp);
+        if (fd == -1){
+            perror(temp);
+            return 1;
+        }
+        write(fd,"12345\n", 6);        
+        stat(temp, &stbuf);
+        create_ts = stbuf.st_mtime;
+        newtime.actime = 0;
+        newtime.modtime = 0;
+        utime(temp,&newtime);
+        addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+        if (addr == MAP_FAILED) {
+            perror("mmap");
+            goto bad_exit;
+        }
+        addr[0]='x';
+        res = msync(addr, 4, MS_ASYNC);
+        if (res == -1) {
+           perror("msync");
+           goto bad_exit;
+        }
+        res = close(fd);        
+        if (res == -1) {
+           perror("close");
+           goto bad_exit;
+        }
+        /* The ASYNC means that we schedule the msync and return immediately.
+           Since we want to see if the modification time is updated upon
+           msync(), we have to make sure that our asynchronous request
+           completes before we stat below. In a real application, the
+           request would be completed at a random time in the future
+           but for this test we do not want to wait an arbitrary amount of
+           time, so force a commit now.  */
+        sync();
+        stat(temp, &stbuf);
+        if (create_ts > stbuf.st_mtime){
+           goto bad_exit;
+        }      
+        unlink(temp);  
+        return 0;
+     bad_exit:
+        unlink(temp);
+        return 1;
+}
+]])],[rd_cv_ms_async=ok],[rd_cv_ms_async=broken],[:])])
+
+
+if test "${rd_cv_ms_async}" = "ok"; then
+ AC_MSG_RESULT(yes)
+else
+ AC_DEFINE_UNQUOTED(HAVE_BROKEN_MS_ASYNC, 1 , [set to 1 if msync with MS_ASYNC fails to update mtime])
+ AC_MSG_RESULT(no)
+ AC_MSG_WARN([With mmap access, your platform fails to update the files])
+ AC_MSG_WARN([mtime. RRDtool will work around this problem by calling utime on each])
+ AC_MSG_WARN([file it opens for rw access.])
+ sleep 2
+fi
+
+])