]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: anticipate Y2038 hack for utmp
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Aug 2023 18:16:12 +0000 (11:16 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Aug 2023 18:18:22 +0000 (11:18 -0700)
* lib/readutmp.c (struct utmpx32): Use unsigned int for tv_sec,
not int, as that is more likely to work after 2038.
Suggested by Andreas Schwab in:
https://sourceware.org/pipermail/libc-alpha/2023-August/150661.html

ChangeLog
lib/readutmp.c

index e1437b1b41519930fbc3f17b579779c9440d706e..80ac7184d83b2e7d3f13d24b24224d328cd483d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-08-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       readutmp: anticipate Y2038 hack for utmp
+       * lib/readutmp.c (struct utmpx32): Use unsigned int for tv_sec,
+       not int, as that is more likely to work after 2038.
+       Suggested by Andreas Schwab in:
+       https://sourceware.org/pipermail/libc-alpha/2023-August/150661.html
+
        diffseq: simplify lint removal
        * lib/diffseq.h (IF_LINT): Remove.
        Instead, always ignore the diagnostic, as that’s simpler
index ac1c851e97fce779bbcd46e5da4feba3387fbad0..b8eba076fab80fb484dd95fd63065b324a928c3b 100644 (file)
@@ -491,7 +491,12 @@ copy_utmp_entry (STRUCT_UTMP *dst, STRUCT_UTMP *src)
     int ut_session;                    /* Session ID, used for windowing.  */
     struct
     {
-      int tv_sec;                      /* Seconds.  */
+      /* Seconds.  Unsigned not signed, as glibc did not exist before 1970,
+         and if the format is still in use after 2038 its timestamps
+         will surely have the sign bit on.  This hack stops working
+         at 2106-02-07 06:28:16 UTC.  */
+      unsigned int tv_sec;
+
       int tv_usec;                     /* Microseconds.  */
     } ut_tv;                           /* Time entry was made.  */
     int ut_addr_v6[4];                 /* Internet address of remote host.  */