bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] gnulib's test for the O_NOATIME open flag is broken


From: Nix
Subject: [PATCH] gnulib's test for the O_NOATIME open flag is broken
Date: Sat, 25 Nov 2006 17:55:36 +0000
User-agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.5-b27 (linux)

The test in m4/fcntl_h.m4 for a working O_NOATIME is never going to work
as it stands (and indeed always fails when coreutils tries to use it).

,----
|  static char const file[] = "confdefs.h";
|  int fd = open (file, O_RDONLY | O_NOATIME);
|  char c;
|  struct stat st0, st1;
|  if (fd < 0
|      || fstat (fd, &st0) != 0
|      || sleep (1) != 0
|      || read (fd, &c, 1) != 1
|      || close (fd) != 0
|      || stat (file, &st1) != 0
|      || st1.st_mtime <= st0.st_mtime
|      || close (fd) != 0)
|     [failure]
`----

Firstly it's checking the mtime, not the atime, which isn't going to get
updated at all because we're opening O_RDONLY, secondly even if the
atime is left unchanged that <= is going to force a failure (surely it's
an error if the two atimes are different in any way at all), and thirdly
that last close() is closing a file that we just closed, which is bound
to return -1 / -EBADF and fail.

I suspect this wasn't noticed because a lot of people mount their
filesystems with the noatime option, so this test would be expected to
fail. nodiratime might be a better mount option for coreutils testing,
at least. (I've gone a bit further and am building in a temporary
loopback filesystem so I can control the mount options precisely, as
well as making sure I'm not on NFS, as NFS caching seems to annoy some
of the coreutils tests at times.)

This patch fixes it.

2006-11-25  Nix  <address@hidden>

        * m4/fcntl_h.m4 (gl_FCNTL_H): Test the atime, not the mtime.
        Don't close an fd more than once. Identical atimes indicate
        success, not failure.

Index: m4/fcntl_h.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/fcntl_h.m4,v
retrieving revision 1.3
diff -u -r1.3 fcntl_h.m4
--- m4/fcntl_h.m4       5 Oct 2006 21:38:10 -0000       1.3
+++ m4/fcntl_h.m4       25 Nov 2006 17:41:12 -0000
@@ -46,8 +46,7 @@
                  || read (fd, &c, 1) != 1
                  || close (fd) != 0
                  || stat (file, &st1) != 0
-                 || st1.st_mtime <= st0.st_mtime
-                 || close (fd) != 0)
+                 || st0.st_atime != st1.st_atime)
                status |= 64;
            }
            return status;]])],

-- 
`The main high-level difference between Emacs and (say) UNIX, Windows,
 or BeOS... is that Emacs boots quicker.' --- PdS




reply via email to

[Prev in Thread] Current Thread [Next in Thread]