Skip to content

needs-restarting: Allow selecting the reboot hint's boot time source - #3098

Open
LUX-ETVERITAS wants to merge 1 commit into
rpm-software-management:mainfrom
LUX-ETVERITAS:feat/needs-restarting-boot-time-source
Open

LUX-ETVERITAS wants to merge 1 commit into
rpm-software-management:mainfrom
LUX-ETVERITAS:feat/needs-restarting-boot-time-source

Conversation

@LUX-ETVERITAS

Copy link
Copy Markdown
Contributor

A machine whose clock is corrected after boot can retain an inaccurate systemd boot timestamp. Administrators can now run dnf5 needs-restarting --boottimesource=kernel to base the reboot hint on btime from /proc/stat. The option also accepts pid1, systemd, and auto. An explicit source reports an error when unavailable. The default keeps the existing systemd lookup and procfs fallback.

Verification

  • Built the plugin and ran seven Behave scenarios covering procfs sources, the automatic fallback, an unavailable systemd source, invalid input, and incompatible modes.
  • Ran the plugin against a private D-Bus service providing UnitsLoadStartTimestamp. The default, auto, and systemd queried the service. The kernel and pid1 selections used procfs directly.

Fixes #2955

Systemd can retain an incorrect timestamp if the clock is corrected
after boot. Let administrators select the kernel boot time, the PID 1
timestamp, or the service manager timestamp explicitly. Report a failed
lookup for an explicit source and retain the automatic fallback when
no source is requested.

Fixes rpm-software-management#2955

Assisted-by: Codex
@LUX-ETVERITAS
LUX-ETVERITAS requested a review from a team as a code owner December 4, 2026 05:38
@LUX-ETVERITAS
LUX-ETVERITAS requested review from jrohel and removed request for a team December 4, 2026 05:38
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

needs-restarting: Allow selecting the reboot hint's boot time source

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes


AI Description

• Adds --boottimesource=auto|systemd|pid1|kernel to select the reboot hint's boot timestamp.
• Explicit sources fail with exit code 1 when unavailable; auto keeps the existing fallback chain.
• Adds Behave scenarios for each source, unknown values, and conflicts with --services and
 --processes.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed selector feeds get_boot_time(), which is consumed by system_needs_restarting() to determine whether installed reboot-suggested packages were installed after boot.
  • The option explicitly conflicts with service and process modes, so this is one bounded end-to-end reboot-detection behavior rather than separate technical-layer capabilities.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, the reboot hint used one systemd-first path with fallback to PID 1 and kernel timestamps.
  • After, four enum values select different branches, with fallback permitted only for auto and explicit nonpositive results becoming errors.
  • The new correctness condition is that source selection, fallback precedence, availability handling, and package-time comparison remain consistent; the existing timestamp readers themselves are extracted or reused rather than newly complex.
Sources

dnf5-plugins/needs_restarting_plugin/needs_restarting.hpp[60-61]

    libdnf5::OptionEnum boot_time_source{"auto", {"auto", "systemd", "pid1", "kernel"}};
    time_t get_systemd_boot_time(Context &);
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the selected or automatically chosen timestamp is wrong, the command can report that reboot is needed when it is not, or fail to report a needed reboot.
  • The command is diagnostic; the supported source-failure path exits without producing a reboot result.
  • Reverting code stops new incorrect calculations, but an already written /run/reboot-required file or an operator action based on the output may require cleanup or correction.
  • Code rollback restores the prior boot-time behavior.
  • A stale /run/reboot-required file may need removal or regeneration, and any operator action based on an incorrect recommendation is outside automatic rollback.
Assessed commit df02c82
Diagram

graph TD
  A["--boottimesource"] --> B{"Source selected"}
  B -->|"systemd"| C["systemd D-Bus"]
  B -->|"auto"| C
  B -->|"pid1"| E["/proc/1 mtime"]
  B -->|"kernel"| F["/proc/stat btime"]
  C -->|"0 or error"| D["max(PID 1, btime)"]
  D --> E
  D --> F
Loading
High-Level Assessment

The PR's approach is sound. A CLI enum linked to the existing boot-time helpers reuses the current lookup code and gives explicit sources a clear failure mode. Automatically detecting clock correction was considered but would need heuristics and risk wrong hints. Keeping the default unchanged avoids behavior changes for existing users.

Files changed (4) +92 / -30

Enhancement (2) +52 / -29
needs_restarting.cppAdd boot time source option and split systemd lookup +49/-29

Add boot time source option and split systemd lookup

• Registers the --boottimesource enum option, conflicting with --services and --processes. Moves the systemd D-Bus lookup into get_systemd_boot_time and dispatches get_boot_time on the selected source. Explicit sources that return no time raise CommandExitError.

dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp

needs_restarting.hppDeclare boot time source enum and systemd helper +3/-0

Declare boot time source enum and systemd helper

• Adds the OptionEnum member with allowed values auto, systemd, pid1, and kernel, defaulting to auto. Declares the new get_systemd_boot_time helper and includes option_enum.hpp.

dnf5-plugins/needs_restarting_plugin/needs_restarting.hpp

Tests (1) +35 / -0
needs-restarting-boot-time-source.featureAdd Behave scenarios for boot time source selection +35/-0

Add Behave scenarios for boot time source selection

• Covers each source without systemd, the explicit systemd failure exit code, unknown value rejection, and conflicts with --services and --processes. The bus address is pointed at a nonexistent socket to simulate systemd being unavailable.

integration-tests/dnf-behave-tests/dnf/plugins-core/needs-restarting-boot-time-source.feature

Documentation (1) +5 / -1
needs_restarting.8.rstDocument --boottimesource option and its behavior +5/-1

Document --boottimesource option and its behavior

• Adds the option to the synopsis and options list. Describes each source, the auto fallback order, the error for unavailable explicit sources, and the conflicts with --services and --processes.

doc/dnf5_plugins/needs_restarting.8.rst

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.

needs-restarting: add option to use btime from /proc/stat instead of "UnitsLoadStartTimestamp"

1 participant