Commit 0b71ff37a7cb0ce546975796f9366eee25be5fb7

Bruno Haible 2023-08-01T21:44:07

readutmp: For year-2038 safety on Linux/{x86,arm}, use systemd APIs. Suggested by Thorsten Kukuk <kukuk@suse.com> in <https://www.thkukuk.de/blog/Y2038_glibc_utmp_64bit/> and <https://github.com/thkukuk/utmpx/blob/main/utmp-to-logind.md>. * m4/systemd.m4: New file. * m4/readutmp.m4 (gl_READUTMP): Require gl_SYSTEMD_CHOICE. Set READUTMP_LIB. Conditionally define READUTMP_USE_SYSTEMD. * lib/readutmp.h: For READUTMP_USE_SYSTEMD, include <sys/time.h> and <utmpx.h>. (struct gl_utmp): New type. (UTMP_STRUCT_NAME, UT_TIME_MEMBER, UT_EXIT_E_TERMINATION, UT_EXIT_E_EXIT, UT_USER, HAVE_STRUCT_XTMP_UT_EXIT, HAVE_STRUCT_XTMP_UT_ID, HAVE_STRUCT_XTMP_UT_PID): Define differently for READUTMP_USE_SYSTEMD. (UT_USER_SIZE): Don't define for READUTMP_USE_SYSTEMD. (UT_TYPE_EQ, UT_TYPE_NOT_DEFINED, READ_UTMP_SUPPORTED): Define also for READUTMP_USE_SYSTEMD. (free_utmp): New declaration. * lib/readutmp.c: Add new includes for READUTMP_USE_SYSTEMD. (extract_trimmed_name): Adapt to READUTMP_USE_SYSTEMD. (get_boot_time_uncached, get_boot_time, guess_pty_name): New functions. (read_utmp): New implementation for READUTMP_USE_SYSTEMD. (free_utmp): New function. * tests/test-readutmp.c (main): At the end, invoke free_utmp. * modules/readutmp (Files): Add m4/systemd.m4. (Link): New section. * modules/readutmp-tests (Makefile.am): Link test-readutmp with READUTMP_LIB. * NEWS: Mention the free_utmp function and the READUTMP_LIB link requirement.