Skip to content

users: add utmp fallback#11579

Open
mattsu2020 wants to merge 3 commits into
uutils:mainfrom
mattsu2020:users
Open

users: add utmp fallback#11579
mattsu2020 wants to merge 3 commits into
uutils:mainfrom
mattsu2020:users

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Gate all feat_systemd_logind #[cfg] attributes with target_os = "linux" so that non-Linux builds (macOS, FreeBSD, etc.) are unaffected by the libsystemd link requirement
  • Fall back to traditional getutxent() when SystemdUtmpxIter::new() fails at runtime, instead of returning an empty iterator

Important 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_logind path 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, users continues to use traditional utmp only and may still print nothing if systemd does not populate /var/run/utmp.

Context

On Ubuntu 26.04, users prints nothing while GNU users correctly shows logged-in users. Modern systemd no longer populates /var/run/utmp, so utilities that rely on it produce no output. The feat_systemd_logind feature was opt-in, meaning default builds never queried systemd-logind.

Manual verification

  • Built with --features feat_systemd_logind on Linux: users uses systemd-logind when logind is available
  • When systemd-logind initialization fails: the iterator falls back to traditional utmp instead of returning an empty iterator
  • Non-Linux builds with feat_systemd_logind enabled: compile correctly without referencing or linking libsystemd (fixed cfg guard)
  • Non-Linux builds without feat_systemd_logind: unchanged behavior

Related to #3219
This PR is related to #3219 but does not address stale utmp entries or PID liveness checks.

@oech3

oech3 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Is this dynamically linked againsyt libsystemd.so? If so, this should be disabled by default.

@mattsu2020

mattsu2020 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Is this dynamically linked againsyt libsystemd.so? If so, this should be disabled by default.

Change to fallback only

@mattsu2020 mattsu2020 changed the title feat: enable systemd-logind by default and add utmp fallback users: add utmp fallback Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Note: The gnu test tests/pr/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/pipe-f is now passing!
Skip an intermittent issue tests/cut/bounded-memory (was skipped on 'main', now failing)

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/tail/tail-n0f. tests/tail/tail-n0f is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

@github-actions

github-actions Bot commented Apr 17, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/cp/sparse-to-pipe. tests/cp/sparse-to-pipe is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/misc/tty-eof (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/basenc/bounded-memory is now being skipped but was previously passing.

- 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.
@codspeed-hq

codspeed-hq Bot commented Jun 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.75%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 145 untouched benchmarks
⏩ 222 skipped benchmarks1

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants