From a6d192b9608516430d95c0255594aa4b003d5ebb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 2 Aug 2023 00:56:25 +0200 Subject: [PATCH] readutmp: Small changes to reduce the code size on the coreutils side. * m4/readutmp.m4 (gl_READUTMP): Test also for the ut_host field in 'struct utmpx' and 'struct utmp'. * lib/readutmp.h (HAVE_STRUCT_XTMP_UT_HOST): New macro. (UT_USER_SIZE): Define also as a macro. Set to -1 if READUTMP_USE_SYSTEMD. (UT_LINE_SIZE, UT_HOST_SIZE): New constants and macros. --- ChangeLog | 10 ++++++++++ lib/readutmp.h | 31 +++++++++++++++++++++++++++++-- m4/readutmp.m4 | 4 +++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16bf75a66d..e7fd56e609 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2023-08-01 Bruno Haible + + readutmp: Small changes to reduce the code size on the coreutils side. + * m4/readutmp.m4 (gl_READUTMP): Test also for the ut_host field in + 'struct utmpx' and 'struct utmp'. + * lib/readutmp.h (HAVE_STRUCT_XTMP_UT_HOST): New macro. + (UT_USER_SIZE): Define also as a macro. Set to -1 if + READUTMP_USE_SYSTEMD. + (UT_LINE_SIZE, UT_HOST_SIZE): New constants and macros. + 2023-08-01 Bruno Haible readutmp: For year-2038 safety on Linux/{x86,arm}, use systemd APIs. diff --git a/lib/readutmp.h b/lib/readutmp.h index e03e0b0a32..06d2a69daf 100644 --- a/lib/readutmp.h +++ b/lib/readutmp.h @@ -252,12 +252,39 @@ struct gl_utmp || HAVE_STRUCT_UTMPX_UT_PID) # endif +# if READUTMP_USE_SYSTEMD +# define HAVE_STRUCT_XTMP_UT_HOST 1 +# else +# define HAVE_STRUCT_XTMP_UT_HOST \ + (HAVE_STRUCT_UTMP_UT_HOST \ + || HAVE_STRUCT_UTMPX_UT_HOST) +# endif + /* Type of entry returned by read_utmp(). */ typedef struct UTMP_STRUCT_NAME STRUCT_UTMP; -/* Size of the UT_USER (ut) member. */ -# if !READUTMP_USE_SYSTEMD +/* Size of the UT_USER (ut) member, or -1 if unbounded. */ +# if READUTMP_USE_SYSTEMD +enum { UT_USER_SIZE = -1 }; +# else enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) }; +# define UT_USER_SIZE UT_USER_SIZE +# endif + +/* Size of the ut->ut_line member, or -1 if unbounded. */ +# if READUTMP_USE_SYSTEMD +enum { UT_LINE_SIZE = -1 }; +# else +enum { UT_LINE_SIZE = sizeof (((STRUCT_UTMP *) 0)->ut_line) }; +# define UT_LINE_SIZE UT_LINE_SIZE +# endif + +/* Size of the ut->ut_host member, or -1 if unbounded. */ +# if READUTMP_USE_SYSTEMD +enum { UT_HOST_SIZE = -1 }; +# else +enum { UT_HOST_SIZE = sizeof (((STRUCT_UTMP *) 0)->ut_host) }; +# define UT_HOST_SIZE UT_HOST_SIZE # endif /* Definition of UTMP_FILE and WTMP_FILE. */ diff --git a/m4/readutmp.m4 b/m4/readutmp.m4 index 2dfd3fe8d0..a4b1cb4642 100644 --- a/m4/readutmp.m4 +++ b/m4/readutmp.m4 @@ -1,4 +1,4 @@ -# readutmp.m4 serial 21 +# readutmp.m4 serial 22 dnl Copyright (C) 2002-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -78,6 +78,8 @@ AC_INCLUDES_DEFAULT AC_CHECK_MEMBERS([struct utmp.ut_type],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_pid],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmp.ut_pid],,,[$utmp_includes]) + AC_CHECK_MEMBERS([struct utmpx.ut_host],,,[$utmp_includes]) + AC_CHECK_MEMBERS([struct utmp.ut_host],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_id],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmp.ut_id],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_exit],,,[$utmp_includes]) -- 2.39.5