feat(detect): use UNIT/USER_UNIT journal fields for service-failure unit names - #1
Merged
Merged
Conversation
…t names
systemd unit names may contain colons (e.g.
`dbus-:1.2-org.kde.KSplash@6.service`), which broke the old `split(':')`
extraction — it truncated the name and fell back to "A systemd unit".
Read the authoritative UNIT/USER_UNIT journal field instead (emitted by
the systemd manager since v198, Jan 2013):
- LogLine gains `unit` and `user_unit` fields
- jsonlog parses UNIT (system manager) / USER_UNIT (user session)
- linux.rs requests both via --output-fields
- detect_service_failure uses the field; USER_UNIT drives a `--user`
scope in the systemctl/journalctl hint (a plain `journalctl -u <user
unit>` returns "No entries")
Also resolve clippy warnings in analysis.rs (manual_contains,
collapsible_if) and oom.rs test (useless vec!).
All 211 tests pass; verified against the live journal.
Co-Authored-By: Claude <noreply@anthropic.com>
Reuse, simplification, efficiency, and altitude fixes from /simplify pass:
analysis.rs:
- Option<&str> instead of empty-string sentinel in bsod_evidence
- param_keys.map() instead of 4 near-identical lines
- Rename shadowed rc_norm → rc_lower/rc_norm
- Extract cycle_to_boot() helper (was duplicated BootCycle construction)
- if/else instead of .or_else(|| (!x).then(|| …))
detect.rs:
- const MARKERS, drop dead trim_start_matches('\'')
- {unit} in format string, ..Default::default() in tests
display.rs:
- Deduped print_cycle_header format string
- json_opt_str helper (replaces 2x .map().unwrap_or_else())
events.rs:
- strip_suffix instead of manual null-terminator index arithmetic
- Reuse wide() from registry.rs (replaces inline encode_utf16().collect())
format.rs:
- is_audio_module() helper takes already-lowercased str (avoids redundant
to_lowercase when caller already has one), shared between
is_audio_power_crash and explain_driver_power_failure
- [.contains()] instead of chained ||
jsonlog.rs:
- Drop identifier gate; field presence alone distinguishes system/user/none
- Plain match instead of find_map over [(key, is_user)] array
registry.rs:
- wide() helper (pub(crate), replaces 4x .encode_utf16().chain([0]).collect())
- .is_ok()/.is_err() directly on WIN32_ERROR
types.rs: derive(Default) on LogLine
oom.rs: ..Default::default() in test helpers
Co-Authored-By: Claude <noreply@anthropic.com>
pickfire
force-pushed
the
feat/unit-field-simplification
branch
from
August 15, 2026 05:52
3cef88d to
0e1af10
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
whyreboot's systemd service-failure detector was broken for unit names containing colons (e.g.dbus-:1.2-org.kde.KSplash@6.service). The old code usedsplit(':').next()on the message text, which truncated the name to just"dbus-"— making thesystemctl statushint useless.Additionally, user-session units (managed by
systemd --user, not PID 1) need--userin the hint, because plainjournalctl -u <user unit>returns "No entries".Solution
Use the
UNITandUSER_UNITjournal fields (emitted by the systemd manager itself since v198, Jan 2013) instead of parsing the message prefix:UNIT— set for system-manager (PID 1) entriesUSER_UNIT— set for user-session entries → drivessystemctl --user/journalctl --userhintThe
--output-fieldsflag now requestsUNIT,USER_UNITalongside the existing fields.Changes
Feature (UNIT/USER_UNIT)
types.rs: Addedunit: Stringanduser_unit: boolfields toLogLine; derivedDefaultjsonlog.rs: ParseUNIT/USER_UNITfrom journald JSON, gated behind identifier checklinux.rs: AddedUNIT,USER_UNITto--output-fieldsdetect.rs: Rewrittendetect_service_failure— usesUNIT/USER_UNITfield, exactcontainsmatch,const MARKERS,--userscopetests/fixtures/mixed.jsonl: Added"UNIT":"nginx.service"to systemd failure lineneeds_systemd_identifier,dbus_transient_unit_name,uses_unit_field_not_message,system_unit_no_user_scope,without_unit_fieldSimplification (review-driven cleanup)
analysis.rs: Option sentinel, param_keys.map(), cycle_to_boot() helper, if/else for annotate_wer_moduledisplay.rs: json_opt_str helper, deduped print_cycle_header formatevents.rs: strip_suffix instead of manual null-terminator arithmeticformat.rs: is_audio_module() helper, [.contains()] for stop codesjsonlog.rs: find_map over [(key, is_user)] arrayregistry.rs: wide() helper, .is_ok()/.is_err() directly on WIN32_ERRORtypes.rs: derive(Default) on LogLineoom.rs: ..Default::default() in test helpersTesting
cargo fmt --all --checkcleancargo clippy --all-targetsclean (Linux +x86_64-pc-windows-gnucross-target)🤖 Generated with Claude Code