public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	libc-alpha <libc-alpha@sourceware.org>,
	Bruno Haible <bruno@clisp.org>, Thorsten Kukuk <kukuk@suse.com>,
	Gnulib bugs <bug-gnulib@gnu.org>
Subject: Re: utmp 64 bit time_t support
Date: Sat, 5 Aug 2023 11:22:44 -0700	[thread overview]
Message-ID: <338f7d65-0334-b9db-73f7-88eb4928c18e@cs.ucla.edu> (raw)
In-Reply-To: <87sf8zqna3.fsf@linux-m68k.org>

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

On 2023-08-04 00:28, Andreas Schwab wrote:
> It could just re-interpret the timestamp field as an unsigned number.

Thanks for suggesting that. Although it a hack, it's likely better than 
the hack that was already in Gnulib, so I installed the attached patch 
into Gnulib. We can use this as an idea for fixing glibc bug 30701.

[-- Attachment #2: 0001-readutmp-anticipate-Y2038-hack-for-utmp.patch --]
[-- Type: text/x-patch, Size: 1870 bytes --]

From 0a7a71a4f24b4608662b4532bd17aef758f049fd Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 5 Aug 2023 11:16:12 -0700
Subject: [PATCH] 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
---
 ChangeLog      | 6 ++++++
 lib/readutmp.c | 7 ++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e1437b1b41..80ac7184d8 100644
--- 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
diff --git a/lib/readutmp.c b/lib/readutmp.c
index ac1c851e97..b8eba076fa 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -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.  */
-- 
2.39.2


      reply	other threads:[~2023-08-05 18:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 20:28 Adhemerval Zanella Netto
2023-08-01 20:46 ` Thorsten Kukuk
2023-08-04  7:00 ` Paul Eggert
2023-08-04  7:28   ` Andreas Schwab
2023-08-05 18:22     ` Paul Eggert [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=338f7d65-0334-b9db-73f7-88eb4928c18e@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=kukuk@suse.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).