Commit 622d2c0763777eb909a4fda5048238f524cc36f9

Bruno Haible 2023-08-08T17:36:10

readutmp: Return entries with unbounded strings on all platforms. Suggested by Paul Eggert in <https://lists.gnu.org/archive/html/bug-gnulib/2023-07/msg00165.html>. * m4/readutmp.m4 (gl_READUTMP): Test also whether struct utmp has an ut_tv member, and whether struct utmp and struct utmpx have an ut_session member. * lib/readutmp.h (struct gl_utmp): Define always. Add ut_exit field. (HAVE_GL_UTMP): Remove macro. (UT_USER, UT_TIME_MEMBER, UT_PID, UT_TYPE_EQ, UT_TYPE_NOT_DEFINED, UT_EXIT_E_TERMINATION, UT_EXIT_E_EXIT, STRUCT_UTMP): Define w.r.t. struct gl_utmp. (UT_USER_SIZE, UT_ID_SIZE, UT_LINE_SIZE, UT_HOST_SIZE): Define to -1 always. (getutent): Remove declaration. (HAVE_STRUCT_XTMP_UT_EXIT): Remove unused macro. (HAVE_STRUCT_XTMP_UT_ID, HAVE_STRUCT_XTMP_UT_PID, HAVE_STRUCT_XTMP_UT_HOST): Change to match the way coreutils uses these macros. * lib/readutmp.c (UT_USER, UT_TIME_MEMBER, UT_PID, UT_TYPE_EQ, UT_TYPE_NOT_DEFINED, IS_USER_PROCESS, UT_EXIT_E_TERMINATION, UT_EXIT_E_EXIT, UT_USER_SIZE, UT_ID_SIZE, UT_LINE_SIZE, UT_HOST_SIZE): Define w.r.t. struct utmpx or struct utmp. (extract_trimmed_name): Don't use UT_USER or UT_USER_SIZE here. (desirable_utmp_entry): Don't use UT_TIME_MEMBER or UT_USER here. (struct utmp_alloc): Define always. (add_utmp): Likewise. Add user_len, id_len, line_len, host_len, termination, exit arguments. Don't require that user, id, line, host are NUL-terminated. Assume user and host are non-NULL. (finish_utmp): New function, extracted from read_utmp. (read_utmp) [READUTMP_USE_SYSTEMD]: Update add_utmp invocations. Pass a non-NULL user and a non-NULL host. Call finish_utmp. (getutent): Move declaration from readutmp.h to here. (copy_utmp_entry): Remove function. (read_utmp) [UTMP_NAME_FUNCTION]: Replace variables n_read, n_alloc, utmp with a 'struct utmp_alloc'. Use 'struct utmpx32' from copy_utmp_entry here. Invoke add_utmp and finish_utmp. (read_utmp) [!UTMP_NAME_FUNCTION]: Replace variables n_read, n_alloc, utmp with a 'struct utmp_alloc'. Invoke add_utmp and finish_utmp. * NEWS: Mention the API change.