Bruno Haible [Fri, 11 Aug 2023 21:20:44 +0000 (23:20 +0200)]
readutmp: Refactor boot time determination code.
* lib/boot-time-aux.h: New file, extracted from lib/readutmp.c.
* lib/readutmp.c: On Linux, include <sys/sysinfo.h> even if
!READUTMP_USE_SYSTEMD.
Include boot-time-aux.h.
(SIZEOF): Remove macro, moved to boot-time-aux.h.
(get_linux_uptime): Remove function, moved to boot-time-aux.h.
(read_utmp_from_file): Invoke get_linux_boot_time_fallback,
get_android_boot_time, get_openbsd_boot_time, get_windows_boot_time.
Code moved to boot-time-aux.h.
(get_boot_time_uncached: Invoke get_linux_boot_time_final_fallback.
Code moved to boot-time-aux.h.
* m4/readutmp.m4 (gl_PREREQ_READUTMP_H): New macro, extracted from
gl_READUTMP.
(gl_READUTMP): Invoke it.
* modules/readutmp (Files): Add lib/boot-time-aux.h.
Bruno Haible [Fri, 11 Aug 2023 14:09:22 +0000 (16:09 +0200)]
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.
Bruno Haible [Fri, 11 Aug 2023 13:22:43 +0000 (15:22 +0200)]
readutmp: Fix the boot time returned on Minix.
* lib/readutmp.c (read_utmp_from_file): [__minix] When the time of the
BOOT_TIME entry is very close to the Epoch, replace it with the time
from the "run-level m" entry.
Bruno Haible [Fri, 11 Aug 2023 12:29:32 +0000 (14:29 +0200)]
readutmp: On Cygwin and Windows, return the boot time.
* lib/readutmp.h (READ_UTMP_SUPPORTED): Define also on native Windows.
* lib/readutmp.c (desirable_utmp_entry): Ignore READ_UTMP_CHECK_PIDS on
Windows.
(read_utmp_from_file): Add a BOOT_TIME entry on Windows.
Bruno Haible [Fri, 11 Aug 2023 00:31:30 +0000 (02:31 +0200)]
readutmp: Tweak the Android specific addition.
* lib/readutmp.c (read_utmp_from_file) [__ANDROID__]: Don't fake a
BOOT_TIME entry if the options request to omit it or if a BOOT_TIME
entry is already present.
Bruno Haible [Thu, 10 Aug 2023 15:23:56 +0000 (17:23 +0200)]
readutmp: Fix the boot time returned on Raspbian.
* lib/readutmp.c (read_utmp_from_file): When the time of the BOOT_TIME
entry is very close to the Epoch, replace it with the time from the
"runlevel"/"~" entry.
Bruno Haible [Thu, 10 Aug 2023 05:59:19 +0000 (07:59 +0200)]
readutmp: Return a boot time also on Android.
* lib/readutmp.c (get_linux_uptime): New function, extracted from
get_boot_time_uncached.
(read_utmp_from_file): Don't look for file time stamps on Android.
Instead, use get_linux_uptime.
(get_boot_time_uncached): Use get_linux_uptime.
Bruno Haible [Wed, 9 Aug 2023 20:52:22 +0000 (22:52 +0200)]
readutmp: Return a boot time also on OpenBSD.
* lib/readutmp.h (BOOT_TIME, USER_PROCESS): Provide fallback
definitions.
* lib/readutmp.c (read_utmp_from_file) [__OpenBSD__]: Fake a BOOT_TIME
entry by looking at the time stamp of a specific file.
Bruno Haible [Wed, 9 Aug 2023 20:27:16 +0000 (22:27 +0200)]
readutmp: Return a boot time also on Alpine Linux.
* lib/readutmp.c: Include stat-time.h.
(SIZEOF): New macro.
(read_utmp_from_file) [__linux__]: Fake a BOOT_TIME entry by looking
at the time stamp of a specific file.
* modules/readutmp (Depends-on): Add stat-time.
Bruno Haible [Wed, 9 Aug 2023 19:12:40 +0000 (21:12 +0200)]
readutmp: Fix boot time in VMs after sleep state and date update.
* lib/readutmp.c (read_utmp_from_file): New function, extracted from
read_utmp.
(get_boot_time_uncached): Before all other approaches, try to find the
boot time in the /var/run/utmp file.
(read_utmp): Invoke read_utmp_from_file.
Bruno Haible [Wed, 9 Aug 2023 16:49:22 +0000 (18:49 +0200)]
readutmp: Make it easier to filter for/against the boot-time entry.
* lib/readutmp.h (READ_UTMP_BOOT_TIME, READ_UTMP_NO_BOOT_TIME): New
enum items.
* lib/readutmp.c (desirable_utmp_entry, read_utmp_from_systemd):
Implement them.
(read_utmp): If no entries can match the given options, return
immediately.
Bruno Haible [Tue, 8 Aug 2023 21:27:38 +0000 (23:27 +0200)]
readutmp: Use classical implementation for files != /var/run/utmp.
* lib/readutmp.c (read_utmp_from_systemd): Renamed from read_utmp
[READUTMP_USE_SYSTEMD]. Remove file argument.
(read_utmp): Call it when the file argument is "/var/run/utmp".
Paul Eggert [Mon, 7 Aug 2023 16:10:21 +0000 (09:10 -0700)]
quotearg: fix obsolete comment
* lib/quotearg.h: Fix comment to match behavior.
This fixes a commentary bug introduced in
commit 1a43a982c927eaf26bbc2701a872009d9be4b33b
"quotearg: do not use grave accent for left quote"
dated 2011-12-18 15:44:17+01, where the comment
was not updated to match the changed behavior.
Paul Eggert [Sun, 6 Aug 2023 19:19:36 +0000 (12:19 -0700)]
Document Android, OpenBSD printf "%n" lack
In doc/posix/functions/*printf*.texi,
document that the POSIX-specified printf functions
do not support the %n format on Android and OpenBSD.
This lack of support is deliberate, as %n is
a common target of attacks on security.
Paul Eggert [Sat, 5 Aug 2023 18:16:12 +0000 (11:16 -0700)]
readutmp: anticipate Y2038 hack for utmp
* lib/readutmp.c (struct utmpx32): Use unsigned int for tv_sec,
not int, as that is more likely to work after 2038.
Suggested by Andreas Schwab in:
https://sourceware.org/pipermail/libc-alpha/2023-August/150661.html
Paul Eggert [Sat, 5 Aug 2023 17:04:41 +0000 (10:04 -0700)]
diffseq: simplify lint removal
* lib/diffseq.h (IF_LINT): Remove.
Instead, always ignore the diagnostic, as that’s simpler
now that we have the pragma change installed in May.
This removes the last IF_LINT from diffutils, though not
the last use of GCC_LINT.
Bruno Haible [Sat, 5 Aug 2023 00:40:03 +0000 (02:40 +0200)]
unistr/{u8-mbtouc,u8-mbsnlen}: Fix test failures (regr. 2023-07-25).
* modules/unistr/u8-mbtouc (configure.ac): Compile this code if the
preinstalled libunistring version is >= 0.9.4, < 1.2.
* modules/unistr/u8-mbsnlen (configure.ac): Likewise.
Paul Eggert [Thu, 3 Aug 2023 23:01:52 +0000 (16:01 -0700)]
readutmp: systemd supports only UTMP_FILE
* lib/readutmp.c (read_utmp): Fail if not UTMP_FILE.
* m4/systemd.m4 (gl_SYSTEMD_CHOICE): Default to no for now,
since yes means "who /var/log/wtmp" stops working.
Paul Eggert [Thu, 3 Aug 2023 23:01:50 +0000 (16:01 -0700)]
readutmp: switch new struct to struct timespec
* lib/readutmp.c (get_boot_time_uncached, get_boot_time)
(add_utmp, read_utmp):
Use struct timespec, not struct timeval.
* lib/readutmp.h: Always include <time.h>, for struct timespec.
Simplify when utmp.h and utmpx.h are included.
(struct gl_utmp): Use the same struct for both the
systemd and the dummy version. Reorder members, and
use proper pid_t type for ut_session. Rename ut_tv to ut_ts
and make it a struct timespec. All uses changed.
(HAVE_GL_UTMP): New macro. Use it where appropriate, instead
of READUTMP_USE_SYSTEMD.
(UT_USER, HAVE_STRUCT_XTMP_UT_EXIT, HAVE_STRUCT_XTMP_UT_ID)
(HAVE_STRUCT_XTMP_UT_PID, HAVE_STRUCT_XTMP_UT_HOST):
Simplify.
* modules/readutmp (Depends-on): Add time-h, timespec_get.
Remove sys_type. Sort.
Paul Eggert [Thu, 3 Aug 2023 22:53:30 +0000 (15:53 -0700)]
readutmp: fix idx_t FIXME in API
* lib/readutmp.c (read_utmp): 2nd arg is now idx_t *, not
size_t *.
* lib/readutmp.h: Include idx.h, for idx_t.
* modules/readutmp (Depends-on): Add idx.
Paul Eggert [Thu, 3 Aug 2023 22:53:27 +0000 (15:53 -0700)]
readutmp: go back to simple ‘free’
Omit the new free_utmp function. Instead, allocate storage
in one block, so that using code can still just call ‘free’.
* lib/readutmp.c (struct utmp_alloc) [READUTMP_USE_SYSTEMD]: New type.
(add_utmp) [READUTMP_USE_SYSTEMD]: New function.
(read_utmp) [READUTMP_USE_SYSTEMD]: Use it.
Also, use malloc a bit less heavily.
(free_utmp): Remove.
* tests/test-readutmp.c (main): Call free, not free_utmp.
Paul Eggert [Thu, 3 Aug 2023 22:31:48 +0000 (15:31 -0700)]
readutmp: simplify extract_trimmed_name via ximemdup0
* lib/readutmp.c (extract_trimmed_name): Simplify.
* modules/readutmp (Depends-on):
Add strnlen, which was a missing dependency.
* lib/readutmp.c: Include xmemdup0.
(extract_trimmed_name): Simplify.
* modules/readutmp (Depends-on): Add xmemdup0.
Add strnlen, which was a missing dependency already.
Bruno Haible [Thu, 3 Aug 2023 16:09:29 +0000 (18:09 +0200)]
alignasof, stdalign: Avoid some -Wundef warnings from config.h.
Reported by Tim Rühsen <tim.ruehsen@gmx.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-08/msg00012.html>.
* m4/stdalign.m4 (gl_ALIGNASOF): Test whether __cplusplus is defined
before evaluating it. Assume HAVE_STDALIGN_H, _GL_STDALIGN_NEEDS_STDDEF
are never defined to 0.
Bruno Haible [Tue, 1 Aug 2023 22:56:25 +0000 (00:56 +0200)]
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.
Bruno Haible [Tue, 1 Aug 2023 19:44:07 +0000 (21:44 +0200)]
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.
Bruno Haible [Mon, 31 Jul 2023 18:33:48 +0000 (20:33 +0200)]
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.
Bruno Haible [Mon, 31 Jul 2023 14:13:11 +0000 (16:13 +0200)]
readutmp: Make the header file and function usable on all platforms.
* lib/readutmp.h (struct gl_utmp, UTMP_STRUCT_NAME, UT_TIME_MEMBER,
UT_EXIT_E_TERMINATION, UT_EXIT_E_EXIT, UT_USER): Provide fallback
definitions.
(READ_UTMP_SUPPORTED): New macro.
* lib/readutmp.c (read_utmp) [!READ_UTMP_SUPPORTED]: Provide a dummy
definition.
* modules/readutmp (Depends-on): Add sys_time.
(configure.ac): Remove conditional.
(Makefile.am): Compile readutmp.c on all platforms.
(Include): Include readutmp.h on all platforms.
* tests/test-readutmp.c: Include readutmp.h on all platforms.
(main): Invoke read_utmp on all platforms.
* lib/readutmp.h (extract_trimmed_name): Add specification comment.
(read_utmp): Move specification comment from lib/readutmp.c to here.
Mention also UTMP_FILE and READ_UTMP_USER_PROCESS.
* lib/readutmp.c (extract_trimmed_name): Fix comment.
* modules/readutmp (Include): Only include the .h file if
HAVE_UTMPX_H || HAVE_UTMP_H.
Paul Eggert [Sun, 30 Jul 2023 00:06:42 +0000 (17:06 -0700)]
readutmp: work around glibc utmpx bug
When compiled with _TIME_BITS=64, glibc <utmpx.h> does not work,
because the files use 32-bit time_t and the code passes this to
the user unmodified, but <utmpx.h> defines a struct with 64-bit
time_t. Work around this compatibility bug. Problem reported
by Jakub Wilk via Sven Joachim <https://bugs.gnu.org/64937>.
* lib/readutmp.c (copy_utmp_entry): New function.
(read_utmp): Use it.
Bruno Haible [Fri, 28 Jul 2023 13:15:26 +0000 (15:15 +0200)]
uchar: Include the necessary snippets.
* lib/uchar.in.h: Add insertion points for _GL_ARG_NONNULL and
_GL_WARN_ON_USE.
* modules/uchar (Depends-on): Add snippet/arg-nonnull,
snippet/warn-on-use.
(Makefile.am): In uchar.h, include the ARG_NONNULL_H and WARN_ON_USE_H
snippets.
Bruno Haible [Fri, 28 Jul 2023 11:56:15 +0000 (13:56 +0200)]
mbmemcasecmp, mbmemcasecoll: Avoid test failure on MSVC.
* tests/test-mbmemcasecmp.h (test_utf_8): Disable two tests on platforms
that don't have the upper/lower mappings for 'ü'/'Ü'.
* tests/test-mbmemcasecmp.c: Include <wchar.h>, <wctype.h>.
* tests/test-mbmemcasecoll.c: Likewise.
* modules/mbmemcasecmp-tests (Depends-on): Add mbrtowc, wctype-h.
* modules/mbmemcasecoll-tests (Depends-on): Likewise.
Bruno Haible [Thu, 27 Jul 2023 20:19:08 +0000 (22:19 +0200)]
fnmatch-h, glob-h tests: Fix link errors (regression 2023-07-24).
* modules/fnmatch-h-c++-tests (Makefile.am): Link test-fnmatch-h-c++
with $(LIBUNISTRING).
* modules/glob-h-c++-tests (Makefile.am): Link test-glob-h-c++ with
$(LIBUNISTRING).
Bruno Haible [Thu, 27 Jul 2023 18:52:36 +0000 (20:52 +0200)]
fnmatch, glob tests: Fix link errors (regression 2023-07-24).
* modules/fnmatch-tests (Makefile.am): Link test-fnmatch-w32 with the
same libraries as test-fnmatch.
* modules/glob (Link): Add $(LIBUNISTRING).
* modules/glob-tests (Makefile.am): Link test-glob with $(LIBUNISTRING).
Bruno Haible [Wed, 26 Jul 2023 13:12:47 +0000 (15:12 +0200)]
wctype: Work around wctype+iswctype bug on MSVC.
* m4/wctype.m4 (gl_FUNC_WCTYPE): In the test program, test also for the
MSVC bug. Update cross-compilation guess.
* doc/posix-functions/wctype.texi: Mention the MSVC bug.
Bruno Haible [Wed, 26 Jul 2023 12:50:00 +0000 (14:50 +0200)]
wctype: Work around wctype bug on mingw.
* lib/wctype.in.h (rpl_wctype_t, wctype_t, GNULIB_defined_wctype_t):
Define if REPLACE_WCTYPE is 1.
(wctype): Consider REPLACE_WCTYPE.
(iswctype): Override also if REPLACE_WCTYPE is 1.
* lib/iswctype.c: If GNULIB_defined_wctype_t is defined, use the
function-pointer based implementation.
* m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_WCTYPE.
* m4/wctype.m4 (gl_FUNC_WCTYPE): Define through AC_DEFUN_ONCE. Test
whether wctype supports the "blank" character class. Set REPLACE_WCTYPE
if not.
* m4/iswctype.m4 (gl_FUNC_ISWCTYPE): Require gl_FUNC_WCTYPE.
* modules/wctype (Status, Notice): Remove.
(Depends-on): Add iswctype. Consider REPLACE_WCTYPE.
(configure.ac): Consider REPLACE_WCTYPE.
* modules/iswctype (Status, Notice): Remove.
(Files): Add m4/wctype.m4.
(configure.ac): Override also if REPLACE_WCTYPE is 1.
* modules/wctype-h (Makefile.am): Substitute REPLACE_WCTYPE.
* doc/posix-functions/wctype.texi: Mention the mingw bug.
Bruno Haible [Wed, 26 Jul 2023 12:13:48 +0000 (14:13 +0200)]
wctype-h: Work around iswprint bug on mingw.
* lib/wctype.in.h (rpl_iswprint): On mingw, don't use the system's
iswprint function.
* tests/test-wctype-h.c (main): Verify that this character class
contains the ASCII space but not tab and newline.
* tests/test-c32isprint.c (main): For tab, \v, \f, expect the same value
on native Windows as on other platforms.
* doc/posix-functions/iswprint.texi: Mention the mingw bug.