utmpx: fall back to systemd-logind on Linux when traditional utmp is empty/unavailable#11579
utmpx: fall back to systemd-logind on Linux when traditional utmp is empty/unavailable#11579mattsu2020 wants to merge 5 commits into
Conversation
|
Is this dynamically linked againsyt libsystemd.so? If so, this should be disabled by default. |
Change to fallback only |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Merging this PR will not alter performance
Comparing Footnotes
|
|
Is there any way to achieve full feature without runtime strong |
|
Or can we believe soname compatibility of systemd and publish them? |
Since I changed it to dynamic load, I'll test to see if this works. |
|
And remove |
|
It seems pure Rust solution is possible: https://github.com/lucab/zbus_systemd (thought maintainer might not want to add such dep...) |
|
nice, ok |
|
Code changes are mostly complete |
|
An additional reason that we want to have this PR: #13212 |
See #8376 (comment) where I explained why I did not use zbus in the implementation of systemd-logind. It is a huge crate. |
…empty On Linux, keep preferring the traditional utmp/utmpx file when it is usable. When the default utmp file is missing or empty (e.g. recent Ubuntu where systemd no longer populates /var/run/utmp), try the systemd-logind backend instead, and fall back to the traditional utmp iterator when libsystemd cannot be loaded, a required symbol is missing, or systemd-logind initialization fails. libsystemd.so.0 is loaded dynamically via libloading (enabled through uucore's `utmpx` feature, Linux only), so the resulting binary has no NEEDED entry for libsystemd and remains usable on systems without it. Additional changes: - Remove the `feat_systemd_logind` opt-in feature and its propagation through `users`, `who`, `pinky`, and `uptime`. - Read the boot time (`who -b` / `uptime -s`) from the kernel's /proc/stat `btime` instead of the /var/lib/systemd/random-seed mtime. - Keep the existing traditional utmp/utmpx behavior on non-Linux. Related to uutils#3219.
The feat_systemd_logind feature was removed, so the grep -v filter is a no-op. Apply the same cleanup already done for the OpenBSD workflow.
Note why traditional_utmp_is_usable stats before opening (opening a non-regular file such as a FIFO could block), and document the window in the fallback-path test where LOCK is released while libc's global utmp path still points at the custom file.
Summary
utmp/utmpxfile when it is usable./var/run/utmp), try the systemd-logind backend instead.libsystemd.so.0dynamically withlibloading, without adding a strong runtime dependency.utmp/utmpxbehavior on non-Linux platforms.feat_systemd_logindopt-in feature and its propagation throughusers,who,pinky, anduptime.who -b/uptime -s) from the kernel's/proc/statbtimeinstead of the/var/lib/systemd/random-seedmodification time, so both report the actual kernel boot time.Motivation
On Ubuntu releases where systemd no longer populates
/var/run/utmp, utilities that read only traditional utmp records can produce empty output even when users are logged in. Keeping systemd-logind support behind an opt-in feature would leave default and published Linux binaries affected unless downstream packagers explicitly enabled it.Dynamic loading allows the Linux default to consult systemd-logind when the traditional utmp file is empty, while keeping the binary usable on systems without libsystemd.
Runtime behavior
On Linux,
iter_all_records()/iter_all_records_from():utmpxrecord, and can be opened. (On musl, the traditional path is treated as never usable, so systemd-logind is always attempted.)libsystemd.so.0and resolve the required sd-login symbols.SystemdLoginApiretains theLibraryhandle for as long as the copied function pointers can be used.iter_all_records_from()continues to use traditional utmp for custom paths. For the default utmp path, it applies the same usable-file check and only tries systemd-logind when the file is missing or empty. When falling back from systemd-logind, it explicitly resetsutmpxname()to the path that was passed in, so a previously selected custom database is not reused accidentally.Dependency behavior
libloadingis enabled through uucore'sutmpxfeature and is compiled only for Linux. The resulting binary has noNEEDEDentry forlibsystemd.so.0; libsystemd is opened only when login records are requested.Verification
Verified in a Linux container:
The Linux fallback regression test passes.
Also verified the users-enabled multicall binary has no strong libsystemd dependency:
Additional checks:
Scope
This PR addresses login-record discovery on Linux systems without a populated utmp database. It does not implement stale utmp entry filtering or login PID liveness checks. DNS canonicalization for systemd-derived records used by
who --lookupandpinky --lookupcan be handled separately.Related to #3219; it does not close that issue.