Skip to content

utmpx: handle unavailable logind session metadata - #16568

Open
mattsu2020 wants to merge 4 commits into
uutils:mainfrom
mattsu2020:utmpx/logind-metadata
Open

mattsu2020 wants to merge 4 commits into
uutils:mainfrom
mattsu2020:utmpx/logind-metadata

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #16478. Related to #8376. Split from #11579.

Review this change.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

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

@mattsu2020
mattsu2020 marked this pull request as ready for review November 17, 2026 05:07
@sylvestre
sylvestre force-pushed the utmpx/logind-metadata branch from 73a2c08 to ebef859 Compare November 17, 2026 05:22
@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 51.62%

2 warnings, 1 note

⚠️ 122 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

⚠️ 12 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

ℹ️ 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

⚡ 14 improved benchmarks
✅ 290 untouched benchmarks
🆕 8 new benchmarks
⏩ 171 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory factor_small_factors_and_a_large_prime 104.8 KB 15.4 KB ×6.8
⚡ CPU Simulation split_lines 14.4 ms 4.3 ms ×3.3
⚡ CPU Simulation split_numeric_suffix 14.6 ms 4.5 ms ×3.2
⚡ CPU Simulation factor_small_factors_and_a_large_prime 1,012.7 µs 681.9 µs +48.51%
⚡ CPU Simulation join_partial_overlap 18.7 ms 15.1 ms +23.45%
⚡ CPU Simulation join_full_match 21.8 ms 18.3 ms +19.26%
⚡ CPU Simulation join_french_locale 21.8 ms 18.3 ms +19.13%
⚡ CPU Simulation join_unicode_locale 2.2 ms 1.8 ms +19.11%
⚡ CPU Simulation join_custom_separator 22.1 ms 18.8 ms +17.77%
⚡ CPU Simulation unexpand_large_file[10] 88.5 ms 83.4 ms +6.14%
⚡ CPU Simulation unexpand_many_lines[100000] 42.6 ms 40.2 ms +6.07%
⚡ CPU Simulation du_wide_tree[(5000, 500)] 16 ms 15.2 ms +5.09%
⚡ CPU Simulation split_number_chunks_round_robin 30.3 ms 28.9 ms +4.86%
⚡ CPU Simulation split_bytes 781.9 µs 755.8 µs +3.45%
🆕 Memory factor_batch_of_largest_u64s N/A 796 KB N/A
🆕 Memory factor_batch_of_semiprimes N/A 199.5 KB N/A
🆕 Memory factor_batch_of_small_numbers N/A 7.5 MB N/A
🆕 Memory factor_batch_of_smallest_u128s N/A 885.9 KB N/A
🆕 CPU Simulation factor_batch_of_largest_u64s N/A 557.4 ms N/A
🆕 CPU Simulation factor_batch_of_semiprimes N/A 794.1 ms N/A
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing mattsu2020:utmpx/logind-metadata (ebef859) with main (fca3de1)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 (8406d69) during the generation of this report, so fca3de1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

continue;
};
let start_time = start_time
.filter(|usec| *usec > 0)

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.

the zero time is checked here, in get_session_start_time and in try_login_time_offset. once should be enough, no?

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


/// Get the login time, or the Unix epoch when it is unavailable.
/// Use [`Self::try_login_time_offset`] when displaying timestamps.
pub fn login_time_offset(&self) -> time::OffsetDateTime {

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.

is this still used outside the test? looks like dead code now, same for the compat login_time()/pid()

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.

The compat login_time() and pid() methods are still used by UtmpxRecord

use super::*;

#[test]
fn missing_metadata_preserves_legacy_api_types() {

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.

what does this test check? the let x: Type lines don't test much

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


#[cfg(test)]
#[path = "systemd_logind/tests.rs"]
mod regression_tests;

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 a second test module in a separate file? please move these into the existing mod tests

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
/// Returns None when logind could not provide a session leader PID.
#[cfg_attr(
not(all(target_os = "linux", feature = "systemd_logind")),
allow(clippy::unnecessary_wraps)

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.

please avoid the allow(), maybe just change pid()/login_time() to return an Option

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/uu/who/src/platform/unix.rs Outdated

#[test]
fn unavailable_time_and_pid_are_question_marks() {
let record = UtmpxRecord::Systemd(SystemdUtmpxCompat::new(SystemdLoginRecord {

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.

the same record is built in 4 tests, could be a small helper in uucore?

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

@mattsu2020
mattsu2020 marked this pull request as draft November 18, 2026 12:30
@mattsu2020
mattsu2020 marked this pull request as ready for review November 18, 2026 12:49

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.

2 participants