users: add utmp fallback#11579
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: |
- Gate all feat_systemd_logind #[cfg] attributes with target_os = "linux" so that non-Linux builds are unaffected by the libsystemd link requirement - Fall back to traditional getutxent() when SystemdUtmpxIter::new() fails at runtime, instead of returning an empty iterator
The fallback branch used `not(feature)` which would cause a compile error on non-Linux platforms with `feat_systemd_logind` enabled, as neither the systemd nor the traditional utmp block would be selected. Also clarify the comment in `next()` to distinguish initialization-time fallback from exclusive iteration.
Merging this PR will improve performance by 4.75%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | ls_recursive_balanced_tree[(6, 4, 15)] |
52.3 ms | 49.6 ms | +5.51% |
| ⚡ | Simulation | ls_recursive_wide_tree[(10000, 1000)] |
34.3 ms | 33 ms | +3.99% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing mattsu2020:users (aad01a4) with main (4223537)
Footnotes
-
222 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Summary
feat_systemd_logind#[cfg]attributes withtarget_os = "linux"so that non-Linux builds (macOS, FreeBSD, etc.) are unaffected by thelibsystemdlink requirementgetutxent()whenSystemdUtmpxIter::new()fails at runtime, instead of returning an empty iteratorImportant notes
This PR does not enable systemd-logind by default and does not change default linking behavior. It only makes the opt-in
feat_systemd_logindpath Linux-only and adds a traditional utmp fallback when systemd-logind initialization fails.Fixing the Ubuntu 26.04 runtime behavior requires downstream builds to enable
feat_systemd_logind. Without that feature,userscontinues to use traditional utmp only and may still print nothing if systemd does not populate/var/run/utmp.Context
On Ubuntu 26.04,
usersprints nothing while GNUuserscorrectly shows logged-in users. Modern systemd no longer populates/var/run/utmp, so utilities that rely on it produce no output. Thefeat_systemd_logindfeature was opt-in, meaning default builds never queried systemd-logind.Manual verification
--features feat_systemd_logindon Linux:usersuses systemd-logind when logind is availablefeat_systemd_logindenabled: compile correctly without referencing or linkinglibsystemd(fixed cfg guard)feat_systemd_logind: unchanged behaviorRelated to #3219
This PR is related to #3219 but does not address stale utmp entries or PID liveness checks.