needs-restarting: Add --exclude-services
Resolves: Resolves: RHEL-56137
This commit is contained in:
parent
0f1af7e187
commit
2d72d988c1
75
0006-needs-restarting-Add-exclude-services.patch
Normal file
75
0006-needs-restarting-Add-exclude-services.patch
Normal file
@ -0,0 +1,75 @@
|
||||
From 204ad06c46b3389aff914528bcb4325bab8ef027 Mon Sep 17 00:00:00 2001
|
||||
From: Evan Goode <mail@evangoo.de>
|
||||
Date: Tue, 24 Sep 2024 21:43:46 +0000
|
||||
Subject: [PATCH 1/2] needs-restarting: Add --exclude-services
|
||||
|
||||
For consumers of `dnf4 needs-restarting`'s output, it's useful to
|
||||
separate the systemd services needing restart vs. the processes not
|
||||
managed by systemd that need restarting. This new `dnf4 needs-restarting
|
||||
--exclude-services` ONLY prints information about processes NOT managed
|
||||
by systemd, and for listing systemd services that need to be restarted,
|
||||
the existing `--services` flag can be used.
|
||||
|
||||
When both `--services` and `--exclude-services` are passed
|
||||
`--exclude-services` is ignored.
|
||||
|
||||
For https://issues.redhat.com/browse/RHEL-56137.
|
||||
---
|
||||
plugins/needs_restarting.py | 27 +++++++++++++++++++++------
|
||||
1 file changed, 21 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py
|
||||
index 86777a2..cbb7a81 100644
|
||||
--- a/plugins/needs_restarting.py
|
||||
+++ b/plugins/needs_restarting.py
|
||||
@@ -264,6 +264,8 @@ class NeedsRestartingCommand(dnf.cli.Command):
|
||||
"(exit code 1) or not (exit code 0)"))
|
||||
parser.add_argument('-s', '--services', action='store_true',
|
||||
help=_("only report affected systemd services"))
|
||||
+ parser.add_argument('--exclude-services', action='store_true',
|
||||
+ help=_("don't list stale processes that correspond to a systemd service"))
|
||||
|
||||
def configure(self):
|
||||
demands = self.cli.demands
|
||||
@@ -303,19 +305,32 @@ class NeedsRestartingCommand(dnf.cli.Command):
|
||||
return None
|
||||
|
||||
stale_pids = set()
|
||||
+ stale_service_names = set()
|
||||
uid = os.geteuid() if self.opts.useronly else None
|
||||
for ofile in list_opened_files(uid):
|
||||
pkg = owning_pkg_fn(ofile.presumed_name)
|
||||
+ pid = ofile.pid
|
||||
if pkg is None:
|
||||
continue
|
||||
- if pkg.installtime > process_start(ofile.pid):
|
||||
- stale_pids.add(ofile.pid)
|
||||
+ 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:
|
||||
+ stale_pids.add(pid)
|
||||
+ else:
|
||||
+ stale_service_names.add(service_name)
|
||||
+ if not self.opts.exclude_services:
|
||||
+ stale_pids.add(pid)
|
||||
+ else:
|
||||
+ # If neither --services nor --exclude-services is set, don't
|
||||
+ # query D-Bus at all.
|
||||
+ stale_pids.add(pid)
|
||||
|
||||
if self.opts.services:
|
||||
- names = set([get_service_dbus(pid) for pid in sorted(stale_pids)])
|
||||
- for name in names:
|
||||
- if name is not None:
|
||||
- print(name)
|
||||
+ for stale_service_name in sorted(stale_service_names):
|
||||
+ print(stale_service_name)
|
||||
return 0
|
||||
+
|
||||
for pid in sorted(stale_pids):
|
||||
print_cmd(pid)
|
||||
--
|
||||
2.47.1
|
||||
|
26
0007-needs-restarting-Add-exclude-services-to-man-page.patch
Normal file
26
0007-needs-restarting-Add-exclude-services-to-man-page.patch
Normal file
@ -0,0 +1,26 @@
|
||||
From d45b5ad95f5fa06d4cfb2a858c2c91cf1355ebd7 Mon Sep 17 00:00:00 2001
|
||||
From: Evan Goode <mail@evangoo.de>
|
||||
Date: Mon, 30 Sep 2024 12:47:57 +0000
|
||||
Subject: [PATCH 2/2] needs-restarting: Add --exclude-services to man page
|
||||
|
||||
---
|
||||
doc/needs_restarting.rst | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/doc/needs_restarting.rst b/doc/needs_restarting.rst
|
||||
index be3cc03..e1fae48 100644
|
||||
--- a/doc/needs_restarting.rst
|
||||
+++ b/doc/needs_restarting.rst
|
||||
@@ -72,6 +72,9 @@ All general DNF options are accepted, see `Options` in :manpage:`dnf(8)` for det
|
||||
``-s, --services``
|
||||
Only list the affected systemd services.
|
||||
|
||||
+``--exclude-services``
|
||||
+ Don't list stale processes that correspond to a systemd service.
|
||||
+
|
||||
-------------
|
||||
Configuration
|
||||
-------------
|
||||
--
|
||||
2.47.1
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
Name: dnf-plugins-core
|
||||
Version: 4.7.0
|
||||
Release: 6%{?dist}
|
||||
Release: 7%{?dist}
|
||||
Summary: Core Plugins for DNF
|
||||
License: GPL-2.0-or-later
|
||||
URL: https://github.com/rpm-software-management/dnf-plugins-core
|
||||
@ -52,6 +52,8 @@ Patch2: 0002-spec-Fix-symbolic-links-to-packaged-files.patch
|
||||
Patch3: 0003-build-Disable-debug-plugin-on-Fedora-40-and-RHEL-9.patch
|
||||
Patch4: 0004-s-Differnt-Different.patch
|
||||
Patch5: 0005-Enable-leaves-and-show-leaves-plugins-for-RHEL.patch
|
||||
Patch6: 0006-needs-restarting-Add-exclude-services.patch
|
||||
Patch7: 0007-needs-restarting-Add-exclude-services-to-man-page.patch
|
||||
BuildArch: noarch
|
||||
BuildRequires: cmake
|
||||
BuildRequires: gettext
|
||||
@ -882,6 +884,10 @@ ln -sf %{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/man1/repotrack.1
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Mon Jan 06 2025 Evan Goode <egoode@redhat.com> - 4.7.0-7
|
||||
- needs-restarting: Add --exclude-services flag
|
||||
Resolves: RHEL-56137
|
||||
|
||||
* Tue Oct 29 2024 Troy Dawson <tdawson@redhat.com> - 4.7.0-6
|
||||
- Bump release for October 2024 mass rebuild:
|
||||
Resolves: RHEL-64018
|
||||
|
Loading…
Reference in New Issue
Block a user