bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

boot-time: straighten code


From: Bruno Haible
Subject: boot-time: straighten code
Date: Fri, 11 Aug 2023 23:49:33 +0200

This set of patches straightens the code of the 'boot-time' module:
Determining the boot time does require iterating through the /var/run/utmpx
file, but it does not require
  - memory allocation,
  - copying of strings,
  - evaluating an options parameter,
  - linking with libsystemd.

So, let me replace the code of this module with a simplified copy of
lib/readutmp.c, while at the same time avoiding large amounts of code
duplication.

Paul: With this simplification, you may consider using the 'boot-time' module
in Emacs. I bet that it produces a better result than Emacs' src/filelock.c
on many platforms. (I haven't tested it, but I could test it if you give me
a manual testing recipe.)


2023-08-11  Bruno Haible  <bruno@clisp.org>

        boot-time: Add comment about multithread-safety.
        * lib/boot-time.h (get_boot_time): Add comment, same as in readutmp.h.

2023-08-11  Bruno Haible  <bruno@clisp.org>

        boot-time: Simplify execution.
        * lib/boot-time.c: Include <stdio.h>, <string.h>, <sys/types.h>,
        <sys/stat.h>, <sys/sysinfo.h>, <time.h>, stat-time.h, unlocked-io.h,
        boot-time-aux.h.
        (UT_USER): New macro, from lib/readutmp.c.
        (getutent): New declaration.
        (get_boot_time_uncached): New function, containing a simplified code
        from lib/readutmp.c.
        (get_boot_time): Don't invoke read_utmp. Instead, invoke
        get_boot_time_uncached and cache the result.
        * modules/boot-time (Files): Add lib/boot-time-aux.h, lib/readutmp.h,
        m4/readutmp.m4.
        (Depends-on): Remove readutmp. Add extensions, fopen-gnu, stat-time,
        stdbool, time-h, timespec_get, unlocked-io-internal.
        (configure.ac): Invoke gl_PREREQ_READUTMP_H.
        (Link): Remove $(READUTMP_LIB). Add $(CLOCK_TIME_LIB).
        * modules/boot-time-tests (Makefile.am): Link test-boot-time with
        $(CLOCK_TIME_LIB), not with $(READUTMP_LIB).

2023-08-11  Bruno Haible  <bruno@clisp.org>

        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.

2023-08-11  Bruno Haible  <bruno@clisp.org>

        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.

Attachment: 0001-readutmp-Make-struct-utmpx32-usable-by-other-code.patch
Description: Text Data

Attachment: 0002-readutmp-Refactor-boot-time-determination-code.patch
Description: Text Data

Attachment: 0003-boot-time-Simplify-execution.patch
Description: Text Data

Attachment: 0004-boot-time-Add-comment-about-multithread-safety.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]