Skip to content

Conversation

@Ecordonnier
Copy link
Contributor

@Ecordonnier Ecordonnier commented Aug 14, 2025

Add support for systemd-logind for systems where /var/run/utmp does not exist any more (e.g. Ubuntu 25.04).

Here is some context explaining the switch from utmp to systemd-logind:
https://www.thkukuk.de/blog/Y2038_glibc_utmp_64bit/

For debian/ubuntu, utmp was disabled in systemd build options in version 256.7 (see https://lists.debian.org/debian-user/2024/11/msg00140.html ). For reference this means that utmp is still enabled in Ubuntu 24.10 and gets disabled first with Ubuntu 25.04 (important for the CI tests).

Fixes #8376

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

@Ecordonnier Ecordonnier marked this pull request as draft August 16, 2025 22:10
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@Ecordonnier Ecordonnier force-pushed the eco/utmp-systemd branch 2 times, most recently from 9e9c61c to 20b4f46 Compare August 17, 2025 21:02
@Ecordonnier Ecordonnier changed the title work in progress - add support for systemd-logind add support for systemd-logind Aug 17, 2025
Add support for systemd-logind for systems where `/var/run/utmp` does not exist any more (e.g. Ubuntu 25.04).

Here is some context explaining the switch from utmp to systemd-logind:
https://www.thkukuk.de/blog/Y2038_glibc_utmp_64bit/

Fixes uutils#8376

Signed-off-by: Etienne Cordonnier <[email protected]>
@Ecordonnier Ecordonnier marked this pull request as ready for review August 17, 2025 21:14
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

@Ecordonnier
Copy link
Contributor Author

I think the PR is good to go (I've undrafted it). Highlighting this comment here, since I had to implement what I consider a GNU coreutils bug to keep uutils-coreutils compatible. On Ubuntu 25.05 "uptime -s" and "who -b" can print a different minute value. I'll try to follow up with GNU coreutils, but I don't know when I will have the time:

    /// Get system boot time using systemd random-seed file fallback
    ///
    /// TODO: This replicates GNU coreutils' fallback behavior for compatibility.
    /// GNU coreutils uses the mtime of /var/lib/systemd/random-seed as a heuristic for boot time
    /// when utmp is unavailable, rather than querying systemd's authoritative KernelTimestamp.
    /// This creates inconsistency: `uptime -s` shows the actual kernel boot time
    /// while `who -b` shows ~1 minute later when systemd services start.
    ///
    /// Ideally, both should use the same source (KernelTimestamp) for semantic consistency.
    /// Consider proposing to GNU coreutils to use systemd's KernelTimestamp property instead.

@cakebaker
Copy link
Contributor

cakebaker commented Aug 20, 2025

There seems to be a bug when using the feat_systemd_logind feature:

$ cargo run -q --features=unix who -b
         system boot  Aug 20 07:35
$ cargo run -q --features=feat_systemd_logind who -b
         system boot  Aug 20 07:35
         system boot  Aug 20 07:35

$ cargo run -q --features=unix users
dho dho dho dho dho dho dho
$ cargo run -q --features=feat_systemd_logind users
dho dho dho dho dho dho dho dho dho

fn new_systemd() -> Self {
// PoisonErrors can safely be ignored
let guard = LOCK.lock().unwrap_or_else(|err| err.into_inner());
let systemd_iter = systemd_logind::SystemdUtmpxIter::new().ok();
Copy link
Contributor

Choose a reason for hiding this comment

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

what happen in case of error here ?
thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reworked that part to return an empty iterator in case of error, and added comments as well

@Ecordonnier
Copy link
Contributor Author

Ecordonnier commented Aug 20, 2025

There seems to be a bug when using the feat_systemd_logind feature:

$ cargo run -q --features=unix who -b
         system boot  Aug 20 07:35
$ cargo run -q --features=feat_systemd_logind who -b
         system boot  Aug 20 07:35
         system boot  Aug 20 07:35

$ cargo run -q --features=unix users
dho dho dho dho dho dho dho
$ cargo run -q --features=feat_systemd_logind users
dho dho dho dho dho dho dho dho dho

Sorry about that. I wasn't hitting this bug on my development machine because 25.04 has no utmp any more. Also something is wrong in the CI setup, because "test_boot()" should have catched this.

It's working now:

ecordonnier@LBM9V6C4:~/dev/coreutils$ cargo run -q --features=unix users
ecordonnier ecordonnier
ecordonnier@LBM9V6C4:~/dev/coreutils$ cargo run -q --features=feat_systemd_logind users
ecordonnier ecordonnier
ecordonnier@LBM9V6C4:~/dev/coreutils$ cargo run -q --features=unix who -b
         system boot  Aug 20 20:41
ecordonnier@LBM9V6C4:~/dev/coreutils$ cargo run -q --features=feat_systemd_logind who -b
         system boot  Aug 20 20:41

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

Ecordonnier and others added 5 commits August 21, 2025 21:17
Co-authored-by: Daniel Hofstetter <[email protected]>
getpwuid() is not thread-safe.

Signed-off-by: Etienne Cordonnier <[email protected]>
Signed-off-by: Etienne Cordonnier <[email protected]>
Signed-off-by: Etienne Cordonnier <[email protected]>
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@Ecordonnier
Copy link
Contributor Author

Maybe something needs to be done about the tests. If running on Ubuntu < 25.04, the tests should use utmp. If running on Ubuntu >= 25.04, the tests should use feat_systemd_logind. This can be automatically detected by using "systemctl --version" which shows whether systemd is compiled with UTMP support or not. This could also be configured manually in the CI files.

Right now cargo test --features feat_systemd_logind is passing in CI, failing on Ubuntu 24.04, and working on Ubuntu 25.04 (GNU coreutils is compiled for systemd-logind support on Ubuntu 25.04).

Please also note that I'm available tomorrow, and then gone for a week.

Signed-off-by: Etienne Cordonnier <[email protected]>
Signed-off-by: Etienne Cordonnier <[email protected]>
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)

@Ecordonnier
Copy link
Contributor Author

Ecordonnier commented Aug 22, 2025

Commit 20f4da0 is not a change requested in the review, however I think it makes sense: with this change, packagers of distributions based on systemd won't need to change anything in the build process and won't accidentally ship e.g. a broken "who".

Edit: I reverted. It will require bigger changes in CI.

This breaks "Tests/BusyBox test suite" in CI.

This reverts commit 16626d4.
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)

@sylvestre sylvestre merged commit bba4d99 into uutils:main Aug 23, 2025
92 checks passed
@Ecordonnier Ecordonnier deleted the eco/utmp-systemd branch August 23, 2025 17:15
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.

who, pinky are empty - need to talk to logind

3 participants