From cdbe33c428a82d42ff6fdcb48815edeb9d9d7fd8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 11 Aug 2023 16:09:22 +0200 Subject: [PATCH] readutmp: Make 'struct utmpx32' usable by other code. * lib/readutmp.h (struct utmpx32): Moved to here from lib/readutmp.c. (UTMP_STRUCT_NAME): Define as utmpx32 if needed. * lib/readutmp.c (read_utmp_from_file): Simply use UTMP_STRUCT_NAME. --- ChangeLog | 7 +++++++ lib/readutmp.c | 33 --------------------------------- lib/readutmp.h | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 526e5cb4be..6836ca6308 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-08-11 Bruno Haible + + readutmp: Make 'struct utmpx32' usable by other code. + * lib/readutmp.h (struct utmpx32): Moved to here from lib/readutmp.c. + (UTMP_STRUCT_NAME): Define as utmpx32 if needed. + * lib/readutmp.c (read_utmp_from_file): Simply use UTMP_STRUCT_NAME. + 2023-08-11 Bruno Haible readutmp tests: Fix link error. diff --git a/lib/readutmp.c b/lib/readutmp.c index 40cee0e58c..00dbbcea48 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -383,40 +383,7 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf, while ((entry = GET_UTMP_ENT ()) != NULL) { -# if __GLIBC__ && _TIME_BITS == 64 - /* This is a near-copy of glibc's struct utmpx, which stops working - after the year 2038. Unlike the glibc version, struct utmpx32 - describes the file format even if time_t is 64 bits. */ - struct utmpx32 - { - short int ut_type; /* Type of login. */ - pid_t ut_pid; /* Process ID of login process. */ - char ut_line[UT_LINE_SIZE]; /* Devicename. */ - char ut_id[UT_ID_SIZE]; /* Inittab ID. */ - char ut_user[UT_USER_SIZE]; /* Username. */ - char ut_host[UT_HOST_SIZE]; /* Hostname for remote login. */ - struct __exit_status ut_exit; /* Exit status of a process marked - as DEAD_PROCESS. */ - /* The fields ut_session and ut_tv must be the same size when compiled - 32- and 64-bit. This allows files and shared memory to be shared - between 32- and 64-bit applications. */ - int ut_session; /* Session ID, used for windowing. */ - struct - { - /* 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. */ - char ut_reserved[20]; /* Reserved for future use. */ - }; - struct utmpx32 const *ut = (struct utmpx32 const *) entry; -# else struct UTMP_STRUCT_NAME const *ut = (struct UTMP_STRUCT_NAME const *) entry; -# endif struct timespec ts = #if (HAVE_UTMPX_H ? 1 : HAVE_STRUCT_UTMP_UT_TV) diff --git a/lib/readutmp.h b/lib/readutmp.h index 70cd3801db..1cf588d265 100644 --- a/lib/readutmp.h +++ b/lib/readutmp.h @@ -132,7 +132,40 @@ enum { UT_HOST_SIZE = -1 }; ⎣ ut_ss struct sockaddr_storage NetBSD, Minix */ -# define UTMP_STRUCT_NAME utmpx +# if __GLIBC__ && _TIME_BITS == 64 +/* This is a near-copy of glibc's struct utmpx, which stops working + after the year 2038. Unlike the glibc version, struct utmpx32 + describes the file format even if time_t is 64 bits. */ +struct utmpx32 +{ + short int ut_type; /* Type of login. */ + pid_t ut_pid; /* Process ID of login process. */ + char ut_line[__UT_LINESIZE]; /* Devicename. */ + char ut_id[4]; /* Inittab ID. */ + char ut_user[__UT_USERSIZE]; /* Username. */ + char ut_host[__UT_HOSTSIZE]; /* Hostname for remote login. */ + struct __exit_status ut_exit; /* Exit status of a process marked + as DEAD_PROCESS. */ + /* The fields ut_session and ut_tv must be the same size when compiled + 32- and 64-bit. This allows files and shared memory to be shared + between 32- and 64-bit applications. */ + int ut_session; /* Session ID, used for windowing. */ + struct + { + /* 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. */ + char ut_reserved[20]; /* Reserved for future use. */ +}; +# define UTMP_STRUCT_NAME utmpx32 +# else +# define UTMP_STRUCT_NAME utmpx +# endif # define SET_UTMP_ENT setutxent # define GET_UTMP_ENT getutxent # define END_UTMP_ENT endutxent -- 2.39.5