From b79e6f56651423c53ba4cee6865c036fc03458df Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 31 Jul 2023 20:33:48 +0200 Subject: [PATCH] readutmp: Revisit portability. * m4/readutmp.m4 (gl_READUTMP): Don't test for struct utmp.ut_exit.ut_*, since no platform has these. * lib/readutmp.h (UT_EXIT_E_TERMINATION): Don't test HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION. (UT_EXIT_E_EXIT): Don't test HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT. * doc/posix-headers/utmpx.texi: Update platforms list. Mention portability problems of specific 'struct utmpx' fields. * doc/glibc-headers/utmp.texi: Update platforms list. Mention portability problems of specific 'struct utmp' fields. --- ChangeLog | 13 ++++++++ doc/glibc-headers/utmp.texi | 22 +++++++++++++- doc/posix-headers/utmpx.texi | 16 +++++++++- lib/readutmp.h | 59 ++++++++++++++++++++++++++++-------- m4/readutmp.m4 | 4 +-- 5 files changed, 97 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index a26958d8b8..dcd2cc58f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2023-07-31 Bruno Haible + + readutmp: Revisit portability. + * m4/readutmp.m4 (gl_READUTMP): Don't test for struct utmp.ut_exit.ut_*, + since no platform has these. + * lib/readutmp.h (UT_EXIT_E_TERMINATION): Don't test + HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION. + (UT_EXIT_E_EXIT): Don't test HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT. + * doc/posix-headers/utmpx.texi: Update platforms list. Mention + portability problems of specific 'struct utmpx' fields. + * doc/glibc-headers/utmp.texi: Update platforms list. Mention + portability problems of specific 'struct utmp' fields. + 2023-07-31 Bruno Haible readutmp: Make argument names consistent. diff --git a/doc/glibc-headers/utmp.texi b/doc/glibc-headers/utmp.texi index 1e9d3757cb..f45037ae74 100644 --- a/doc/glibc-headers/utmp.texi +++ b/doc/glibc-headers/utmp.texi @@ -23,7 +23,7 @@ Portability problems fixed by Gnulib: @itemize @item This header file is missing on some platforms: -FreeBSD 13.0, mingw, MSVC 14. +FreeBSD 13.2, mingw, MSVC 14. @item @code{} is a prerequisite of @code{} on some platforms: FreeBSD 8.0, OpenBSD 7.2. @@ -32,6 +32,26 @@ FreeBSD 8.0, OpenBSD 7.2. Portability problems not fixed by Gnulib: @itemize @item +While some platforms have the @code{struct utmp} field @code{ut_user}, +older platforms have the field @code{ut_name}. +@item +The @code{struct utmp} fields @code{ut_id}, @code{ut_pid}, @code{ut_type} +do not exist on some platforms: +macOS, old FreeBSD, NetBSD, OpenBSD, Minix. +@item +The @code{struct utmp} field @code{ut_host} does not exist on some platforms: +IRIX, Solaris. +@item +The @code{struct utmp} field @code{ut_exit} does not exist on some platforms: +macOS, old FreeBSD, NetBSD, OpenBSD, Minix, Cygwin. +@item +The @code{struct utmp} field @code{ut_session} does not exist on some platforms: +macOS, old FreeBSD, NetBSD, OpenBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin. +@item +The @code{struct utmp} field @code{ut_addr} or @code{ut_addr_v6} does not exist +on some platforms: +macOS, old FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Solaris. +@item On some platforms, this API does not support timestamps past the year 2038: glibc 2.38 on 32-bit platforms like x86 and ARM where @code{time_t} diff --git a/doc/posix-headers/utmpx.texi b/doc/posix-headers/utmpx.texi index fd3d4d6ab7..40efca3b64 100644 --- a/doc/posix-headers/utmpx.texi +++ b/doc/posix-headers/utmpx.texi @@ -13,7 +13,21 @@ Portability problems not fixed by Gnulib: @itemize @item This header file is missing on some platforms: -FreeBSD 6.0, OpenBSD 6.7, Minix 3.1.8, mingw, MSVC 14, Android 9.0. +FreeBSD 8.4, OpenBSD 7.2, Minix 3.1.8, mingw, MSVC 14, Android 13.0. +@item +While some platforms have the @code{struct utmpx} field @code{ut_user}, +older platforms have the field @code{ut_name}. +@item +The @code{struct utmpx} field @code{ut_exit} does not exist on some platforms: +macOS, FreeBSD, AIX, Cygwin. +@item +The @code{struct utmpx} field @code{ut_session} does not exist +on some platforms: +macOS, FreeBSD, AIX, HP-UX, Cygwin. +@item +The @code{struct utmpx} field @code{ut_addr} or @code{ut_addr_v6} or +@code{ut_ss} does not exist on some platforms: +macOS, FreeBSD, AIX, IRIX, Solaris. @item On some platforms, this API does not support timestamps past the year 2038: diff --git a/lib/readutmp.h b/lib/readutmp.h index 0ddd724c22..271dd4921a 100644 --- a/lib/readutmp.h +++ b/lib/readutmp.h @@ -39,6 +39,28 @@ # if HAVE_UTMPX_H +/* defines 'struct utmpx' with the following fields: + + Field Type Platforms + ---------- ------ --------- + ⎡ ut_user char[] glibc, musl, macOS, FreeBSD, AIX, HP-UX, IRIX, Solaris, Cygwin + ⎣ ut_name char[] NetBSD, Minix + ut_id char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ut_line char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ut_pid pid_t glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ut_type short glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ⎡ ut_tv struct glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ⎢ { tv_sec; tv_usec; } + ⎣ ut_time time_t Cygwin + ut_host char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ut_exit struct glibc, musl, NetBSD, Minix, HP-UX, IRIX, Solaris + { e_termination; e_exit; } + ut_session [long] int glibc, musl, NetBSD, Minix, IRIX, Solaris + ⎡ ut_addr [long] int HP-UX, Cygwin + ⎢ ut_addr_v6 [u]int[4] glibc, musl + ⎣ ut_ss struct sockaddr_storage NetBSD, Minix + */ + # if HAVE_UTMP_H /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE. */ # include @@ -63,7 +85,7 @@ # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION # define UT_EXIT_E_TERMINATION(UT) ((UT)->ut_exit.e_termination) # else -# if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION +# if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION /* OSF/1 */ # define UT_EXIT_E_TERMINATION(UT) ((UT)->ut_exit.ut_termination) # else # define UT_EXIT_E_TERMINATION(UT) 0 @@ -73,7 +95,7 @@ # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT # define UT_EXIT_E_EXIT(UT) ((UT)->ut_exit.e_exit) # else -# if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT +# if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT /* OSF/1 */ # define UT_EXIT_E_EXIT(UT) ((UT)->ut_exit.ut_exit) # else # define UT_EXIT_E_EXIT(UT) 0 @@ -82,6 +104,27 @@ # elif HAVE_UTMP_H +/* defines 'struct utmp' with the following fields: + + Field Type Platforms + ---------- ------ --------- + ⎡ ut_user char[] glibc, musl, AIX, HP-UX, IRIX, Solaris, Cygwin, Android + ⎣ ut_name char[] macOS, old FreeBSD, NetBSD, OpenBSD, Minix + ut_id char[] glibc, musl, AIX, HP-UX, IRIX, Solaris, Cygwin, Android + ut_line char[] glibc, musl, macOS, old FreeBSD, NetBSD, OpenBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android + ut_pid pid_t glibc, musl, AIX, HP-UX, IRIX, Solaris, Cygwin, Android + ut_type short glibc, musl, AIX, HP-UX, IRIX, Solaris, Cygwin, Android + ⎡ ut_tv struct glibc, musl, Android + ⎢ { tv_sec; tv_usec; } + ⎣ ut_time time_t macOS, old FreeBSD, NetBSD, OpenBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin + ut_host char[] glibc, musl, macOS, old FreeBSD, NetBSD, OpenBSD, Minix, AIX, HP-UX, Cygwin, Android + ut_exit struct glibc, musl, AIX, HP-UX, IRIX, Solaris, Android + { e_termination; e_exit; } + ut_session [long] int glibc, musl, Android + ⎡ ut_addr [long] int HP-UX, Cygwin + ⎣ ut_addr_v6 [u]int[4] glibc, musl, Android + */ + # include # if !HAVE_DECL_GETUTENT struct utmp *getutent (void); @@ -98,21 +141,13 @@ # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION # define UT_EXIT_E_TERMINATION(UT) ((UT)->ut_exit.e_termination) # else -# if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION -# define UT_EXIT_E_TERMINATION(UT) ((UT)->ut_exit.ut_termination) -# else -# define UT_EXIT_E_TERMINATION(UT) 0 -# endif +# define UT_EXIT_E_TERMINATION(UT) 0 # endif # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT # define UT_EXIT_E_EXIT(UT) ((UT)->ut_exit.e_exit) # else -# if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT -# define UT_EXIT_E_EXIT(UT) ((UT)->ut_exit.ut_exit) -# else -# define UT_EXIT_E_EXIT(UT) 0 -# endif +# define UT_EXIT_E_EXIT(UT) 0 # endif # else diff --git a/m4/readutmp.m4 b/m4/readutmp.m4 index 82254d21e8..44fcc6151b 100644 --- a/m4/readutmp.m4 +++ b/m4/readutmp.m4 @@ -1,4 +1,4 @@ -# readutmp.m4 serial 20 +# readutmp.m4 serial 21 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, @@ -48,12 +48,10 @@ AC_INCLUDES_DEFAULT AC_CHECK_MEMBERS([struct utmp.ut_exit],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_exit.ut_exit],,,[$utmp_includes]) - AC_CHECK_MEMBERS([struct utmp.ut_exit.ut_exit],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_exit.e_exit],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmp.ut_exit.e_exit],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_exit.ut_termination],,,[$utmp_includes]) - AC_CHECK_MEMBERS([struct utmp.ut_exit.ut_termination],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmpx.ut_exit.e_termination],,,[$utmp_includes]) AC_CHECK_MEMBERS([struct utmp.ut_exit.e_termination],,,[$utmp_includes]) fi -- 2.39.5