]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: Ensure multithread-safety.
authorBruno Haible <bruno@clisp.org>
Fri, 4 Aug 2023 12:50:04 +0000 (14:50 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 4 Aug 2023 12:50:04 +0000 (14:50 +0200)
* lib/readutmp.c (get_boot_time): Initialize 'cached' after 'boot_time',
not before. Also declare both as volatile.

ChangeLog
lib/readutmp.c

index dc30f193f0ffa3d1e2736d3893fe6b797cf5787a..7e9c04111ee690f094b234aba8ec7a85137fdf89 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-08-04  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: Ensure multithread-safety.
+       * lib/readutmp.c (get_boot_time): Initialize 'cached' after 'boot_time',
+       not before. Also declare both as volatile.
+
 2023-08-04  Bruno Haible  <bruno@clisp.org>
 
        readutmp tests: Fix gcc warning (regression from yesterday).
index c692b3854d57c6465390f2f2fb707c71b158f06b..01c02ad36e1d4b8b6d2dbefe7bcbd71673e3133a 100644 (file)
@@ -152,13 +152,13 @@ get_boot_time_uncached (void)
 static struct timespec
 get_boot_time (void)
 {
-  static bool cached;
-  static struct timespec boot_time;
+  static bool volatile cached;
+  static struct timespec volatile boot_time;
 
   if (!cached)
     {
-      cached = true;
       boot_time = get_boot_time_uncached ();
+      cached = true;
     }
   return boot_time;
 }