teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0140-cgtop-Do-not-rewrite-P-or-k-options.patch

ac3a84
From 1672b8dd340c4d4aa6398a08b15b36368ba442ec Mon Sep 17 00:00:00 2001
ac3a84
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
ac3a84
Date: Fri, 25 Nov 2022 17:50:27 +0100
ac3a84
Subject: [PATCH] cgtop: Do not rewrite -P or -k options
ac3a84
ac3a84
--recursive=no will overwrite possible -P or -k option hence making the
ac3a84
recursive disabling impossible.
ac3a84
ac3a84
Check what counting types the system supports (encoded in the ordering
ac3a84
of our enum) of and pick whatever user requests but is also supported.
ac3a84
ac3a84
Fixes: #25248
ac3a84
(cherry picked from commit 48600b3524afe05d0faa8a5c88b5aaa53b801199)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/cgtop/cgtop.c | 16 ++++++++++------
ac3a84
 1 file changed, 10 insertions(+), 6 deletions(-)
ac3a84
ac3a84
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
ac3a84
index 95c3987525..8a51a9371b 100644
ac3a84
--- a/src/cgtop/cgtop.c
ac3a84
+++ b/src/cgtop/cgtop.c
ac3a84
@@ -55,6 +55,12 @@ typedef struct Group {
ac3a84
         uint64_t io_input_bps, io_output_bps;
ac3a84
 } Group;
ac3a84
 
ac3a84
+typedef enum PidsCount {
ac3a84
+        COUNT_USERSPACE_PROCESSES,
ac3a84
+        COUNT_ALL_PROCESSES,
ac3a84
+        COUNT_PIDS,
ac3a84
+} PidsCount;
ac3a84
+
ac3a84
 static unsigned arg_depth = 3;
ac3a84
 static unsigned arg_iterations = UINT_MAX;
ac3a84
 static bool arg_batch = false;
ac3a84
@@ -65,11 +71,7 @@ static char* arg_root = NULL;
ac3a84
 static bool arg_recursive = true;
ac3a84
 static bool arg_recursive_unset = false;
ac3a84
 
ac3a84
-static enum {
ac3a84
-        COUNT_PIDS,
ac3a84
-        COUNT_USERSPACE_PROCESSES,
ac3a84
-        COUNT_ALL_PROCESSES,
ac3a84
-} arg_count = COUNT_PIDS;
ac3a84
+static PidsCount arg_count = COUNT_PIDS;
ac3a84
 
ac3a84
 static enum {
ac3a84
         ORDER_PATH,
ac3a84
@@ -915,6 +917,7 @@ static int run(int argc, char *argv[]) {
ac3a84
         usec_t last_refresh = 0;
ac3a84
         bool quit = false, immediate_refresh = false;
ac3a84
         _cleanup_free_ char *root = NULL;
ac3a84
+        PidsCount possible_count;
ac3a84
         CGroupMask mask;
ac3a84
         int r;
ac3a84
 
ac3a84
@@ -928,7 +931,8 @@ static int run(int argc, char *argv[]) {
ac3a84
         if (r < 0)
ac3a84
                 return log_error_errno(r, "Failed to determine supported controllers: %m");
ac3a84
 
ac3a84
-        arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES;
ac3a84
+        possible_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_ALL_PROCESSES;
ac3a84
+        arg_count = MIN(possible_count, arg_count);
ac3a84
 
ac3a84
         if (arg_recursive_unset && arg_count == COUNT_PIDS)
ac3a84
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),