]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp, boot-time: Work around a Cygwin 3.5.3 bug.
authorBruno Haible <bruno@clisp.org>
Sat, 4 May 2024 14:36:06 +0000 (16:36 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 17 May 2024 22:58:18 +0000 (00:58 +0200)
Reported by Ken Brown <kbrown@cornell.edu> in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00035.html>.

* lib/boot-time-aux.h (get_windows_boot_time): On Cygwin, ignore
pagefile.sys if it appears to be a directory, and use another file as
a fallback.

ChangeLog
lib/boot-time-aux.h

index 4eeba0f52cb65bcf100385ed79c5281ecbfebe8e..61df52a7121b8ab3a83f6b0dcb48058c96b2a860 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-05-04  Bruno Haible  <bruno@clisp.org>
+
+       readutmp, boot-time: Work around a Cygwin 3.5.3 bug.
+       Reported by Ken Brown <kbrown@cornell.edu> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00035.html>.
+       * lib/boot-time-aux.h (get_windows_boot_time): On Cygwin, ignore
+       pagefile.sys if it appears to be a directory, and use another file as
+       a fallback.
+
 2024-05-03  Simon Josefsson  <simon@josefsson.org>
 
        maint.mk: Don't fail on ~/.indent.pro, reported by Collin Funk.
index a94cdb3f302ed3055c6a3cbe84533aa58cbd62e6..7f8c5405e4c09e03b0c926734c8439298014043c 100644 (file)
@@ -304,19 +304,35 @@ get_windows_boot_time (struct timespec *p_boot_time)
      Instead, on Windows, the boot time can be retrieved by looking at the
      time stamp of a file that (normally) gets touched only during the boot
      process, namely C:\pagefile.sys.  */
-  const char * const boot_touched_file =
-    #if defined __CYGWIN__ && !defined _WIN32
-    /* It is more portable to use /proc/cygdrive/c than /cygdrive/c.  */
-    "/proc/cygdrive/c/pagefile.sys"
-    #else
-    "C:\\pagefile.sys"
-    #endif
-    ;
-  struct stat statbuf;
-  if (stat (boot_touched_file, &statbuf) >= 0)
+  const char * const boot_touched_files[] =
     {
-      *p_boot_time = get_stat_mtime (&statbuf);
-      return 0;
+      #if defined __CYGWIN__ && !defined _WIN32
+      /* It is more portable to use /proc/cygdrive/c than /cygdrive/c.  */
+      "/proc/cygdrive/c/pagefile.sys",
+      /* A fallback, working around a Cygwin 3.5.3 bug.  It has a modification
+         time about 1.5 minutes after the last boot; but that's better than
+         nothing.  */
+      "/proc/cygdrive/c/ProgramData/Microsoft/Windows/DeviceMetadataCache/dmrc.idx"
+      #else
+      "C:\\pagefile.sys"
+      #endif
+    };
+  for (idx_t i = 0; i < SIZEOF (boot_touched_files); i++)
+    {
+      const char *filename = boot_touched_files[i];
+      struct stat statbuf;
+      if (stat (filename, &statbuf) >= 0)
+        {
+# if defined __CYGWIN__ && !defined _WIN32
+          /* Work around a Cygwin 3.5.3 bug.
+             <https://cygwin.com/pipermail/cygwin/2024-May/255931.html>  */
+          if (!S_ISDIR (statbuf.st_mode))
+# endif
+            {
+              *p_boot_time = get_stat_mtime (&statbuf);
+              return 0;
+            }
+        }
     }
   return -1;
 }