summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dd72cf8)
raw | patch | inline | side by side (parent: dd72cf8)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Fri, 5 Dec 2008 15:18:11 +0000 (15:18 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Fri, 5 Dec 2008 15:18:11 +0000 (15:18 +0000) |
the mtime does not get updated. warn and explicitly call utime
in rrd_open when a file is opened rw.
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1696 a5681a0c-68f1-0310-ab6d-d61299d08faa
in rrd_open when a file is opened rw.
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1696 a5681a0c-68f1-0310-ab6d-d61299d08faa
acinclude.m4 | patch | blob | history | |
configure.ac | patch | blob | history | |
src/rrd_open.c | patch | blob | history |
diff --git a/acinclude.m4 b/acinclude.m4
index 38ee0c29f69347d63e9e6f25d50d116822925558..5ea34f0f54a3047beb0f8b89c1b8706747d985fc 100644 (file)
--- a/acinclude.m4
+++ b/acinclude.m4
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
-dnl ---------------------------------------------------------------------------
-dnl CF_DISABLE_ECHO version: 10 updated: 2003/04/17 22:27:11
-dnl ---------------
-dnl stolen from xterm aclocal.m4
-dnl
-dnl You can always use "make -n" to see the actual options, but it's hard to
-dnl pick out/analyze warning messages when the compile-line is long.
-dnl
-dnl Sets:
-dnl ECHO_LT - symbol to control if libtool is verbose
-dnl ECHO_LD - symbol to prefix "cc -o" lines
-dnl RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
-dnl SHOW_CC - symbol to put before explicit "cc -c" lines
-dnl ECHO_CC - symbol to put before any "cc" line
-dnl
-AC_DEFUN([CF_DISABLE_ECHO],[
-AC_MSG_CHECKING(if you want to see long compiling messages)
-CF_ARG_DISABLE(echo,
- [ --disable-echo display "compiling" commands],
- [
- ECHO_LT='--silent'
- ECHO_LD='@echo linking [$]@;'
- RULE_CC=' @echo compiling [$]<'
- SHOW_CC=' @echo compiling [$]@'
- ECHO_CC='@'
-],[
- ECHO_LT=''
- ECHO_LD=''
- RULE_CC='# compiling'
- SHOW_CC='# compiling'
- ECHO_CC=''
])
-AC_MSG_RESULT($enableval)
-AC_SUBST(ECHO_LT)
-AC_SUBST(ECHO_LD)
-AC_SUBST(RULE_CC)
-AC_SUBST(SHOW_CC)
-AC_SUBST(ECHO_CC)
-])dnl
+
diff --git a/configure.ac b/configure.ac
index b3d5c8060ce762460060245d0eea0c39f6b821e0..0d39a7b41dbaf29fd36bb402e08aee140b6c3ed1 100644 (file)
--- a/configure.ac
+++ b/configure.ac
CONFIGURE_PART(Resolve Portability Issues)
+CHECK_FOR_WORKING_MS_ASYNC
+
dnl Do we need getopt_long
build_getopt=no
diff --git a/src/rrd_open.c b/src/rrd_open.c
index 5598546d11ae471cad5c4fa332e565829cfc53ed..5a908daafc49a01eb285f0d205e246c4af8829ef 100644 (file)
--- a/src/rrd_open.c
+++ b/src/rrd_open.c
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <utime.h>
#include "rrd_tool.h"
#include "unused.h"
} else {
if (rdwr & RRD_READWRITE) {
flags |= O_RDWR;
-#ifdef HAVE_MMAP
- rrd_simple_file->mm_flags = MAP_SHARED;
- rrd_simple_file->mm_prot |= PROT_WRITE;
-#endif
}
if (rdwr & RRD_CREAT) {
flags |= (O_CREAT | O_TRUNC);
goto out_free;
}
+#ifdef HAVE_MMAP
+#ifdef HAVE_BROKEN_MS_ASYNC
+ if (rdwr & RRD_READWRITE) {
+ /* some unices, the files mtime does not get update
+ on msync MS_ASYNC, in order to help them,
+ we update the the timestamp at this point.
+ The thing happens pretty 'close' to the open
+ call so the chances of a race should be minimal.
+
+ Maybe ask your vendor to fix your OS ... */
+ utime(file_name,NULL);
+ }
+#endif
+#endif
+
/* Better try to avoid seeks as much as possible. stat may be heavy but
* many concurrent seeks are even worse. */
if (newfile_size == 0 && ((fstat(rrd_simple_file->fd, &statb)) < 0)) {
if (data != MAP_FAILED)
munmap(data, rrd_file->file_len);
#endif
+
close(rrd_simple_file->fd);
out_free:
free(rrd_file->pvt);