Skip to content

utmpx: fall back to logind when default utmp is unavailable - #11579

Open
mattsu2020 wants to merge 1 commit into
uutils:mainfrom
mattsu2020:users
Open

mattsu2020 wants to merge 1 commit into
uutils:mainfrom
mattsu2020:users

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

When Linux's default utmp has no complete record, try logind for who, users, pinky and uptime. Keep populated traditional files first.

Related to #3219 and #8376; zbus support follows in #16231.

@oech3

This comment was marked as resolved.

@mattsu2020

This comment was marked as resolved.

@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:

Congrats! The gnu test tests/env/env0-from is no longer failing!

@codspeed

codspeed Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 124 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 312 untouched benchmarks
⏩ 171 skipped benchmarks1


Comparing mattsu2020:users (b8a5387) with main (c44859c)2

Open in CodSpeed

Footnotes

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

  2. No successful run was found on main (35012ad) during the generation of this report, so c44859c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@oech3

This comment was marked as resolved.

@mattsu2020
mattsu2020 marked this pull request as draft June 27, 2026 05:04
@mattsu2020 mattsu2020 changed the title users: add utmp fallback users: dynamically load libsystemd with utmp fallback Jun 27, 2026
@mattsu2020

This comment was marked as resolved.

@oech3

This comment was marked as resolved.

@oech3

oech3 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

It seems pure Rust solution is possible: https://github.com/lucab/zbus_systemd (thought maintainer might not want to add such dep...)

@HackingRepo

Copy link
Copy Markdown
Contributor

nice, ok

@mattsu2020 mattsu2020 changed the title users: dynamically load libsystemd with utmp fallback utmpx: prefer systemd-logind on Linux with utmp fallback Jun 27, 2026
@mattsu2020 mattsu2020 changed the title utmpx: prefer systemd-logind on Linux with utmp fallback utmpx: fall back to systemd-logind on Linux when traditional utmp is empty/unavailable Jun 27, 2026
@mattsu2020
mattsu2020 marked this pull request as ready for review June 27, 2026 07:43
@mattsu2020

This comment was marked as resolved.

@oech3

oech3 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

An additional reason that we want to have this PR: #13212

@Ecordonnier

Copy link
Copy Markdown
Collaborator

It seems pure Rust solution is possible: https://github.com/lucab/zbus_systemd (thought maintainer might not want to add such dep...)

See #8376 (comment) where I explained why I did not use zbus in the implementation of systemd-logind. It is a huge crate.

@Ecordonnier

Copy link
Copy Markdown
Collaborator

Will it still be compatible with GNU coreutils behavior? how much is it deviating? the goal of the initial implementation of systemd-logind was to have the same behavior than GNU coreutils.

@mattsu2020

Copy link
Copy Markdown
Contributor Author

https://github.com/mattsu2020/coreutils/tree/users-zbus
I tried implementing it using zbus, but it ended up increasing the binary size.

@oech3

oech3 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

I think it is acceptible since libsystemd.so itself is large enough. We increased binary size when we dropped oniguruma. But it is not a real disadvantage.

@mattsu2020 mattsu2020 changed the title utmpx: fall back to systemd-logind on Linux when traditional utmp is empty/unavailable utmpx: fall back to runtime-loaded logind on Linux Nov 7, 2026
@mattsu2020

Copy link
Copy Markdown
Contributor Author

I think it is acceptible since libsystemd.so itself is large enough. We increased binary size when we dropped oniguruma. But it is not a real disadvantage.

I've reworked the PR to use zbus, as I determined that the increase in binary size is not significant enough to be a concern.

@mattsu2020
mattsu2020 marked this pull request as ready for review November 7, 2026 05:17
@mattsu2020
mattsu2020 marked this pull request as draft November 7, 2026 09:41
@mattsu2020
mattsu2020 force-pushed the users branch 4 times, most recently from 537d701 to 4e451f9 Compare November 10, 2026 06:35
@mattsu2020 mattsu2020 changed the title utmpx: fall back to runtime-loaded logind on Linux utmpx: fall back to logind when default utmp is unavailable Nov 15, 2026
@xtqqczze

This comment was marked as outdated.

Comment thread src/uucore/src/lib/features/utmpx.rs Outdated
const UTMP_LOCK_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);

#[cfg(all(target_os = "linux", not(target_env = "musl")))]
fn lock_utmp(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we reimplement getutxent() with our own fcntl locking on linux?
this is a lot of new code unrelated to the logind fallback, please split it into another pr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

let api = ffi::SystemdLoginApi::load().map_err(|e| {
USimpleError::new(
1,
crate::translate!("systemd-logind-error-load-library", "error" => e),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error is thrown away by read_logind(options).ok() in utmpx.rs, so nobody will see it
do we need the translation, the two ftl entries and the test in locale.rs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

Comment thread src/uucore/src/lib/features/utmpx.rs Outdated
/// The default requests both fields. Traditional utmp records and the boot
/// timestamp are unaffected.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReadOptions {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need ReadOptions? asking logind for the start time and the leader is cheap, and every caller would get simpler

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed ReadOptions.

Comment thread src/uucore/src/lib/features/utmpx.rs Resolved
Comment thread src/uucore/src/lib/features/utmpx.rs Resolved
Comment thread src/uucore/src/lib/features/utmpx.rs Resolved
Comment thread src/uucore/src/lib/features/utmpx.rs Resolved
@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the patch!
The main blocker is the new Linux utmp reader, the one that replaces getutxent(): please split it into another PR (details inline).
Please also rebase so only your commits are left, and squash them into a single commit.

@oech3

oech3 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

I think we should use zbus at least for static musl.

@mattsu2020

Copy link
Copy Markdown
Contributor Author

I think we should use zbus at least for static musl.

I'll consider handling static musl separately to keep this PR focused.

This branch has not been deployed

No deployments
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.

6 participants