needs-restarting: Don't suggest restarting NEED_REBOOT

Resolves: RHEL-98293
This commit is contained in:
Marek Blaha 2026-07-15 13:55:53 +02:00
parent eb2c68d3ae
commit 185afd620b
2 changed files with 127 additions and 1 deletions

View File

@ -0,0 +1,122 @@
From a9e4ea96ebde0691fd5d29901d648ba8639a4743 Mon Sep 17 00:00:00 2001
From: Marek Blaha <mblaha@redhat.com>
Date: Tue, 9 Jun 2026 11:45:29 +0000
Subject: [PATCH] needs-restarting: Don't suggest restarting NEED_REBOOT
services (RHEL-98293)
"needs-restarting -s" used to list services like dbus-broker.service
for restart after package updates. Restarting dbus-broker breaks
system logins, firewalld, and other D-Bus clients.
Services whose unit file is provided by a NEED_REBOOT package are now
excluded from the -s stdout and reported as a warning on stderr
instead.
The -r mode and default mode (no flags) are unchanged.
For: https://redhat.atlassian.net/browse/RHEL-98293
Original upstream commit: ca40caa
Signed-off-by: Marek Blaha <mblaha@redhat.com>
---
doc/needs_restarting.rst | 4 +++-
plugins/needs_restarting.py | 38 ++++++++++++++++++++++++++++++-------
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/doc/needs_restarting.rst b/doc/needs_restarting.rst
index fea407e..4e2074b 100644
--- a/doc/needs_restarting.rst
+++ b/doc/needs_restarting.rst
@@ -74,7 +74,9 @@ All general DNF options are accepted, see `Options` in :manpage:`dnf(8)` for det
Only report whether a reboot is required (exit code 1) or not (exit code 0).
``-s, --services``
- Only list the affected systemd services.
+ Only list the affected systemd services that can be safely restarted.
+ Services that should not be restarted (such as ``dbus-broker``) are
+ excluded and reported as a warning on stderr.
``--exclude-services``
Don't list stale processes that correspond to a systemd service.
diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py
index 8e01aba..50726e1 100644
--- a/plugins/needs_restarting.py
+++ b/plugins/needs_restarting.py
@@ -34,6 +34,7 @@ import functools
import os
import re
import stat
+import sys
import time
@@ -163,7 +164,12 @@ def get_service_dbus(pid):
'Id'
)
if name.endswith(".service"):
- return name
+ # FragmentPath is the path to the unit file that defines the service
+ fragment_path = service_properties.Get(
+ "org.freedesktop.systemd1.Unit",
+ 'FragmentPath'
+ )
+ return name, fragment_path
return
def smap2opened_file(pid, line):
@@ -361,7 +367,7 @@ class NeedsRestartingCommand(dnf.cli.Command):
return None
stale_pids = set()
- stale_service_names = set()
+ stale_services = {}
uid = os.geteuid() if self.opts.useronly else None
for ofile in list_opened_files(uid):
pkg = owning_pkg_fn(ofile.presumed_name)
@@ -371,11 +377,12 @@ class NeedsRestartingCommand(dnf.cli.Command):
if pkg.installtime <= process_start(pid):
continue
if self.opts.services or self.opts.exclude_services:
- service_name = get_service_dbus(pid)
- if service_name is None:
+ result = get_service_dbus(pid)
+ if result is None:
stale_pids.add(pid)
else:
- stale_service_names.add(service_name)
+ service_name, fragment_path = result
+ stale_services[service_name] = fragment_path
if not self.opts.exclude_services:
stale_pids.add(pid)
else:
@@ -384,8 +391,25 @@ class NeedsRestartingCommand(dnf.cli.Command):
stale_pids.add(pid)
if self.opts.services:
- for stale_service_name in sorted(stale_service_names):
- print(stale_service_name)
+ installed_need_reboot_pkgs = set()
+ for pkg in self.base.sack.query().installed().filterm(
+ provides=NEED_REBOOT):
+ installed_need_reboot_pkgs.add(pkg.name)
+ reboot_service_names = set()
+ for svc, fragment_path in stale_services.items():
+ if fragment_path:
+ unit_pkg = owning_pkg_fn(fragment_path)
+ if unit_pkg and \
+ unit_pkg.name in installed_need_reboot_pkgs:
+ reboot_service_names.add(svc)
+ for svc in sorted(set(stale_services) - reboot_service_names):
+ print(svc)
+ if reboot_service_names:
+ print(_('Warning: The following services should not be '
+ 'restarted but require a reboot:'),
+ file=sys.stderr)
+ for name in sorted(reboot_service_names):
+ print(' %s' % name, file=sys.stderr)
return 0
for pid in sorted(stale_pids):
--
2.55.0

View File

@ -42,7 +42,7 @@
Name: dnf-plugins-core
Version: 4.7.0
Release: 10%{?dist}
Release: 11%{?dist}
Summary: Core Plugins for DNF
License: GPL-2.0-or-later
URL: https://github.com/rpm-software-management/dnf-plugins-core
@ -58,6 +58,7 @@ Patch8: 0008-needs-restarting-Get-boot-time-from-systemd-UnitsLoa.patch
Patch9: 0009-doc-needs-restarting-uses-UnitsLoadStartTimestamp-bo.patch
Patch10: 0010-reposync-Avoid-multiple-downloads-of-duplicate-packa.patch
Patch11: 0011-versionlock-Document-that-local-packages-are-not-aff.patch
Patch12: 0012-needs-restarting-Don-t-suggest-restarting-NEED_REBOO.patch
BuildArch: noarch
BuildRequires: cmake
@ -889,6 +890,9 @@ ln -sf %{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/man1/repotrack.1
%endif
%changelog
* Wed Jul 15 2026 Marek Blaha <mblaha@redhat.com> - 4.7.0-11
- needs-restarting: Don't suggest restarting NEED_REBOOT services (RHEL-98293)
* Wed Dec 03 2025 Petr Pisar <ppisar@redhat.com> - 4.7.0-10
- Document that local packages are not affected by versionlock (RHEL-94828)