← Back to Pull requests

tests/utmpx: check logind timestamps and leader PIDs #16231

Open
mattsu2020 opened this pull request with 2148 lines diff across 25 files
View on GitHub
mattsu2020 mattsu2020 commented on Nov 06, 2026 23:07 UTC
Author

Check the login time in who -u and pinky, and the session leader PID in who -u. Verify that each field displays ? when sd-login cannot supply its value.

Depends on #11579.

Diff: 2148 lines (+1870 / -278) across 25 files Reviewer: oech3 Review duration: 39634m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.72) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 2148 lines diff across 25 files
0.72
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
36 items
github-actions[bot] github-actions[bot] commented on Nov 06, 2026 23:17 UTC
Bot

<!-- gnu-comment-bot -->
GNU testsuite comparison:

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

github-actions[bot] github-actions[bot] commented on Nov 06, 2026 23:42 UTC
Bot

<!-- size-comment-bot -->
Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.61 MB (+224 KB, +0.14%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

mattsu2020 mattsu2020 commented on Nov 07, 2026 01:05 UTC
Author

Personally, I prefer the zbus-based approach because I find it allows for cleaner code.

oech3 oech3 commented on code on Nov 07, 2026 04:05 UTC
Code Review
docs/src/wasi-test-gaps.md:1
@@ -22,6 +22,11 @@ The WASI specification requires that argv entries and filenames are valid UTF-8.
 
 WASI does not support creating or opening FIFOs (named pipes). Tests that use `mkfifo` are skipped.
 
+## WASI: no native dynamic library loading

Is this really needed? It would bever implemented at wasi side and we don't document same things for Windows.

oech3 oech3 commented on code on Nov 07, 2026 04:06 UTC
Code Review
.vscode/cspell.dictionaries/workspace.wordlist.txt:1
@@ -1,6 +1,7 @@
 # * cargo
 cdylib
 doctest
+libloading

You no nonger dlopen.

oech3 oech3 commented on code on Nov 07, 2026 04:06 UTC
Code Review
.vscode/cspell.dictionaries/workspace.wordlist.txt:1
@@ -186,6 +187,7 @@ execvp
 fdatasync
 freeaddrinfo
 getaddrinfo
+dlopen

You no longer dlopen *.so.

codspeed[bot] codspeed[bot] commented on Nov 07, 2026 04:50 UTC
Bot

<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->

Merging this PR will regress 3 benchmarks

<details>
<summary><b>2 warnings, 1 note</b></summary>

:warning: 118 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

:warning: 5 benchmarks with a significant change ran on different hardware

> Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

> Learn more about Macro Runners

> See affected benchmarks

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

</details>

⚡ 2 improved benchmarks
❌ 3 regressed benchmarks
✅ 408 untouched benchmarks
⏩ 70 skipped benchmarks[^skipped]

[!WARNING]

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

| | Mode | Benchmark | BASE | HEAD | Efficiency |
| --- | ---- | --------- | ------ | ------ | ---------- |
| ❌ | CPU Simulation | [` socket_addrs_direct[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Ausers-zbus?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Asocket_addrs_direct%255B100000%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 105.3 µs | 132.9 µs | -20.78% |
| ❌ | Memory | [
cp_recursive_deep_tree[(120, 4)] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Ausers-zbus?uri=src%2Fuu%2Fcp%2Fbenches%2Fcp_bench.rs%3A%3Acp_recursive_deep_tree%255B%28120%252C%25204%29%255D&runnerMode=Memory&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 670.5 KB | 788.5 KB | -14.97% |
| ❌ | CPU Simulation | [
hostname_ip_lookup[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Ausers-zbus?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Ahostname_ip_lookup%255B100000%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 544 µs | 573.6 µs | -5.16% |
| ⚡ | Memory | [
socket_addrs_direct[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Ausers-zbus?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Asocket_addrs_direct%255B100000%255D&runnerMode=Memory&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 68 KB | 8.6 KB | ×7.9 |
| ⚡ | Memory | [
hostname_ip_lookup[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Ausers-zbus?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Ahostname_ip_lookup%255B100000%255D&runnerMode=Memory&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 159.7 KB | 100.3 KB | +59.19% |

[!TIP]

Investigate this regression by commenting @codspeedbot fix this regression` on this PR, or directly use the CodSpeed MCP with your agent.

---

<sub>Comparing <code>mattsu2020:users-zbus</code> (66dc25c) with <code>main</code> (dded1b5)</sub>

<a href="https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Ausers-zbus?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>

[^skipped]: 70 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.

mattsu2020 mattsu2020 commented on code on Nov 07, 2026 05:11 UTC
Code Review
.vscode/cspell.dictionaries/workspace.wordlist.txt:1
@@ -186,6 +187,7 @@ execvp
 fdatasync
 freeaddrinfo
 getaddrinfo
+dlopen

Not needed. Delete it

mattsu2020 mattsu2020 commented on code on Nov 07, 2026 05:17 UTC
Code Review
.vscode/cspell.dictionaries/workspace.wordlist.txt:1
@@ -1,6 +1,7 @@
 # * cargo
 cdylib
 doctest
+libloading

I added this because the spell checker reported an error.

mattsu2020 mattsu2020 commented on code on Nov 07, 2026 05:18 UTC
Code Review
docs/src/wasi-test-gaps.md:1
@@ -22,6 +22,11 @@ The WASI specification requires that argv entries and filenames are valid UTF-8.
 
 WASI does not support creating or opening FIFOs (named pipes). Tests that use `mkfifo` are skipped.
 
+## WASI: no native dynamic library loading

That's true. Delete the text.

oech3 oech3 commented on code on Nov 07, 2026 05:23 UTC
Code Review
tests/fixtures/who/logind_redirect.rs:1

I think we can use binaries provided by systemd itself at our test and remove unsafe dlopen.

mattsu2020 mattsu2020 commented on code on Nov 07, 2026 05:53 UTC
Code Review
tests/fixtures/who/logind_redirect.rs:1

I'm running some basic tests, but it looks like we can remove it.

oech3 oech3 commented on code on Nov 07, 2026 10:47 UTC
Code Review
.github/workflows/CICD.yml:1
@@ -42,6 +42,27 @@ jobs:
         persist-credentials: false
     - uses: EmbarkStudios/cargo-deny-action@v2
 
+  logind:
+    name: Logind/${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, ubuntu-24.04]

Why both?

oech3 oech3 commented on code on Nov 07, 2026 10:50 UTC
Code Review
deny.toml:1
@@ -9,7 +9,12 @@ db-urls = ["https://github.com/rustsec/advisory-db"]
 version = 2
 yanked = "warn"
 ignore = [
-  #"RUSTSEC-0000-0000",
+  # These crates were merged into zbus 6, which requires Rust 1.89.

This is valid reason to bump our Rust at different PR. https://ubuntu.com/developers/docs/reference/availability/rust/

mattsu2020 mattsu2020 commented on code on Nov 07, 2026 11:24 UTC
Code Review
.github/workflows/CICD.yml:1
@@ -42,6 +42,27 @@ jobs:
         persist-credentials: false
     - uses: EmbarkStudios/cargo-deny-action@v2
 
+  logind:
+    name: Logind/${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, ubuntu-24.04]

Ubuntu 22.04 tests the D-Bus fallback used by older systemd versions.
Ubuntu 24.04 tests direct access through newer sd-login APIs.
Both are needed to cover these different code paths.
If testing just one of them is sufficient, I'll consolidate them into one.

mattsu2020 mattsu2020 commented on code on Nov 07, 2026 11:27 UTC
Code Review
deny.toml:1
@@ -9,7 +9,12 @@ db-urls = ["https://github.com/rustsec/advisory-db"]
 version = 2
 yanked = "warn"
 ignore = [
-  #"RUSTSEC-0000-0000",
+  # These crates were merged into zbus 6, which requires Rust 1.89.

Is there any reason we can't upgrade to Rust 1.89?
If not, I'd prefer to upgrade to 1.89 first.
If we're aiming to align with Ubuntu, should we upgrade to Rust 1.93?

xtqqczze xtqqczze commented on code on Nov 07, 2026 11:38 UTC
Code Review
deny.toml:1
@@ -9,7 +9,12 @@ db-urls = ["https://github.com/rustsec/advisory-db"]
 version = 2
 yanked = "warn"
 ignore = [
-  #"RUSTSEC-0000-0000",
+  # These crates were merged into zbus 6, which requires Rust 1.89.
xtqqczze xtqqczze commented on code on Nov 09, 2026 15:47 UTC
Code Review
.github/workflows/CICD.yml:1
@@ -42,6 +42,27 @@ jobs:
         persist-credentials: false
     - uses: EmbarkStudios/cargo-deny-action@v2
 
+  logind:
+    name: Logind/${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, ubuntu-24.04]

ubuntu-22.04 runner image is deprecated and will be retired in April 2027, how can we test it then?

mattsu2020 mattsu2020 commented on code on Nov 09, 2026 22:14 UTC
Code Review
.github/workflows/CICD.yml:1
@@ -42,6 +42,27 @@ jobs:
         persist-credentials: false
     - uses: EmbarkStudios/cargo-deny-action@v2
 
+  logind:
+    name: Logind/${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, ubuntu-24.04]

Ubuntu's LTS support period is relatively short. How about using Debian instead? I think that could work.

oech3 oech3 commented on code on Nov 09, 2026 22:16 UTC
Code Review
.github/workflows/CICD.yml:1
@@ -42,6 +42,27 @@ jobs:
         persist-credentials: false
     - uses: EmbarkStudios/cargo-deny-action@v2
 
+  logind:
+    name: Logind/${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, ubuntu-24.04]

GitHub does not provide it. Do we really need to care about legacy API?
We should support what user want to do at 1st.

mattsu2020 mattsu2020 commented on code on Nov 09, 2026 22:40 UTC
Code Review
.github/workflows/CICD.yml:1
@@ -42,6 +42,27 @@ jobs:
         persist-credentials: false
     - uses: EmbarkStudios/cargo-deny-action@v2
 
+  logind:
+    name: Logind/${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, ubuntu-24.04]

I think it would be better to run CI/CD tests only on the latest version and remove the Ubuntu 22.04 image.

Since we already have unit tests in place, I believe this should be sufficient.

sylvestre sylvestre commented on Nov 17, 2026 21:04 UTC
Contributor

thanks for the patch!
The zbus part makes who and pinky 58% bigger, just for systemd < 254. See the comment on bus.rs.
Please also wait until #11579 and #16255 land, rebase on them, and squash everything into one commit.

sylvestre sylvestre commented on code on Nov 17, 2026 21:04 UTC
Code Review
src/uucore/src/lib/features/systemd_logind/bus.rs:1
@@ -0,0 +1,110 @@
+// This file is part of the uutils coreutils package.
+//
+// For the full copyright and license information, please view the LICENSE
+// file that was distributed with this source code.
+
+//! Compatibility with logind versions predating the session time/leader APIs.
+
+use async_io::Timer;
+use futures_lite::FutureExt;
+use std::collections::HashMap;
+use std::future::Future;
+use std::time::Duration;
+use zbus::{Connection, OwnedObjectPath, OwnedVariant};
+
+use crate::utmpx::ReadOptions;
+
+const DESTINATION: &str = "org.freedesktop.login1";
+
+#[derive(Default)]
+pub(super) struct SessionDetails {
+    pub(super) start_time: Option<u64>,
+    pub(super) leader: Option<u32>,
+}
+
+pub(super) fn session_details(

this costs +58% on who and pinky (~700KB) only for systemd < 254, is it worth it?
printing ? there seems good enough to me

sylvestre sylvestre commented on code on Nov 17, 2026 21:04 UTC
Code Review
src/uucore/src/lib/features/systemd_logind.rs:1
@@ -383,6 +551,21 @@ pub fn read_login_records() -> UResult<Vec<SystemdLoginRecord>> {
         }
     }
 
+    let details = session_details(missing_details);
+    for record in &mut records {
+        if let Some(details) = details.get(&record.session_id) {
+            if record.login_time == UNIX_EPOCH {
+                record.login_time = details
+                    .start_time
+                    .and_then(|usec| UNIX_EPOCH.checked_add(std::time::Duration::from_micros(usec)))

same conversion as line 454, could be dedup

sylvestre sylvestre commented on code on Nov 17, 2026 21:04 UTC
Code Review
tests/by-util/test_split.rs:1
@@ -944,6 +946,8 @@ fn test_suffix_auto_width_with_number() {
 fn test_suffix_start_too_large(#[case] args: &[&str], #[case] input: &str) {
     new_ucmd!()
         .args(args)
+        // Argument validation can close stdin before the writer finishes.
+        .ignore_stdin_write_error()

now called twice, and unrelated to this PR, please drop it from here

mattsu2020 mattsu2020 commented on code on Nov 18, 2026 12:53 UTC
Code Review
src/uucore/src/lib/features/systemd_logind/bus.rs:1
@@ -0,0 +1,110 @@
+// This file is part of the uutils coreutils package.
+//
+// For the full copyright and license information, please view the LICENSE
+// file that was distributed with this source code.
+
+//! Compatibility with logind versions predating the session time/leader APIs.
+
+use async_io::Timer;
+use futures_lite::FutureExt;
+use std::collections::HashMap;
+use std::future::Future;
+use std::time::Duration;
+use zbus::{Connection, OwnedObjectPath, OwnedVariant};
+
+use crate::utmpx::ReadOptions;
+
+const DESTINATION: &str = "org.freedesktop.login1";
+
+#[derive(Default)]
+pub(super) struct SessionDetails {
+    pub(super) start_time: Option<u64>,
+    pub(super) leader: Option<u32>,
+}
+
+pub(super) fn session_details(

I'm fine with that approach.

mattsu2020 mattsu2020 commented on code on Nov 20, 2026 22:57 UTC
Code Review
src/uucore/src/lib/features/systemd_logind.rs:1
@@ -383,6 +551,21 @@ pub fn read_login_records() -> UResult<Vec<SystemdLoginRecord>> {
         }
     }
 
+    let details = session_details(missing_details);
+    for record in &mut records {
+        if let Some(details) = details.get(&record.session_id) {
+            if record.login_time == UNIX_EPOCH {
+                record.login_time = details
+                    .start_time
+                    .and_then(|usec| UNIX_EPOCH.checked_add(std::time::Duration::from_micros(usec)))

fixed it

mattsu2020 mattsu2020 commented on code on Nov 20, 2026 22:57 UTC
Code Review
tests/by-util/test_split.rs:1
@@ -944,6 +946,8 @@ fn test_suffix_auto_width_with_number() {
 fn test_suffix_start_too_large(#[case] args: &[&str], #[case] input: &str) {
     new_ucmd!()
         .args(args)
+        // Argument validation can close stdin before the writer finishes.
+        .ignore_stdin_write_error()

fixed it

xtqqczze xtqqczze commented on code on Nov 28, 2026 16:05 UTC
Code Review
src/uu/uptime/Cargo.toml:1
@@ -23,10 +23,12 @@ clap = { workspace = true }
 fluent = { workspace = true }
 jiff = { workspace = true }
 thiserror = { workspace = true }
-uucore = { workspace = true, features = ["libc", "utmpx", "uptime"] }
-
-[features]
-systemd_logind = ["uucore/systemd_logind"]
+uucore = { workspace = true, features = [
+  "libc",
+  "utmpx",

alphabetize please

xtqqczze xtqqczze commented on code on Nov 28, 2026 16:06 UTC
Code Review
src/uu/pinky/Cargo.toml:1
@@ -20,10 +20,7 @@ doctest = false
 [target.'cfg(any(target_vendor = "apple", target_os = "cygwin", target_os = "freebsd", target_os = "linux", target_os = "netbsd"))'.dependencies]
 clap = { workspace = true }
 fluent = { workspace = true }
-uucore = { workspace = true, features = ["utmpx", "entries"] }
-
-[features]
-systemd_logind = ["uucore/systemd_logind"]
+uucore = { workspace = true, features = ["utmpx", "systemd-logind", "entries"] }

alphabetize please

xtqqczze xtqqczze commented on code on Nov 28, 2026 16:06 UTC
Code Review
src/uu/users/Cargo.toml:1
@@ -19,7 +19,7 @@ test = false
 doctest = false
 
 [target.'cfg(any(target_vendor = "apple", target_os = "cygwin", target_os = "freebsd", target_os = "linux", target_os = "netbsd"))'.dependencies]
-uucore = { workspace = true, features = ["utmpx"] }
+uucore = { workspace = true, features = ["utmpx", "systemd-logind"] }

alphabetize please

xtqqczze xtqqczze commented on code on Nov 28, 2026 16:06 UTC
Code Review
src/uu/who/Cargo.toml:1
@@ -15,17 +15,13 @@ readme.workspace = true
 
 [lib]
 path = "src/who.rs"
-test = false
 doctest = false
 
 [target.'cfg(any(target_vendor = "apple", target_os = "cygwin", target_os = "freebsd", target_os = "linux", target_os = "netbsd"))'.dependencies]
 clap = { workspace = true }
 fluent = { workspace = true }
 rustix = { workspace = true, features = ["fs", "termios"] }
-uucore = { workspace = true, features = ["utmpx"] }
-
-[features]
-systemd_logind = ["uucore/systemd_logind"]
+uucore = { workspace = true, features = ["utmpx", "systemd-logind"] }

alphabetize please

xtqqczze xtqqczze commented on code on Nov 28, 2026 16:07 UTC
Code Review
src/uucore/Cargo.toml:1
@@ -234,14 +236,14 @@ sum = [
   "data-encoding",
   "zeroed-alloc",
 ]
-systemd_logind = ["utmpx", "libc"]
 # Use OpenSSL (libcrypto) for md5/sha1/sha2-family digests instead of the
 # pure-Rust crates. This dramatically speeds up checksum utilities on CPUs
 # without SHA-NI by using OpenSSL's optimized assembly implementations.
 openssl = ["dep:openssl"]
 update-control = ["parser"]
 utf8 = []
 utmpx = ["time", "time/macros", "libc", "dns-lookup"]
+systemd-logind = ["utmpx", "dep:libloading"]

alphabetize please

xtqqczze xtqqczze commented on code on Nov 28, 2026 16:07 UTC
Code Review
Cargo.toml:1
@@ -442,6 +443,8 @@ openssl = [
 ]
 # "test_risky_names" == enable tests that create problematic file names (would make a network share inaccessible to Windows, breaks SVN on Mac OS, etc.)
 test_risky_names = []
+# Linux logind integration tests.
+test_logind = ["who", "pinky", "users", "uptime"]

alphabetize please

xtqqczze xtqqczze commented on Nov 28, 2026 16:09 UTC
Contributor

does each commit stand alone, or should they be squashed?

Reviewers
Assignees
mattsu2020 mattsu2020
Labels
risk: low confidence: 87.4% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 71.5% (HIGH) · Higher = larger blast radius
71.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 87.4% · Lower = rushed or shallow review
87.4%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 9% · Safe to merge
9%