diff options
author | Michal Koutný <mkoutny@suse.com> | 2022-11-25 17:50:27 +0100 |
---|---|---|
committer | Michal Koutný <mkoutny@suse.com> | 2022-11-28 14:29:49 +0100 |
commit | 48600b3524afe05d0faa8a5c88b5aaa53b801199 (patch) | |
tree | 3a29ff6e9f71b4a43e745780438d99165d502b61 /src/cgtop | |
parent | mkfs-util: Drop batch (b) and n flags from mcopy (diff) | |
download | systemd-48600b3524afe05d0faa8a5c88b5aaa53b801199.tar.xz systemd-48600b3524afe05d0faa8a5c88b5aaa53b801199.zip |
cgtop: Do not rewrite -P or -k options
--recursive=no will overwrite possible -P or -k option hence making the
recursive disabling impossible.
Check what counting types the system supports (encoded in the ordering
of our enum) of and pick whatever user requests but is also supported.
Fixes: #25248
Diffstat (limited to 'src/cgtop')
-rw-r--r-- | src/cgtop/cgtop.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index cf51024dcb..cef5b654e7 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -56,6 +56,12 @@ typedef struct Group { uint64_t io_input_bps, io_output_bps; } Group; +typedef enum PidsCount { + COUNT_USERSPACE_PROCESSES, + COUNT_ALL_PROCESSES, + COUNT_PIDS, +} PidsCount; + static unsigned arg_depth = 3; static unsigned arg_iterations = UINT_MAX; static bool arg_batch = false; @@ -66,11 +72,7 @@ static char* arg_root = NULL; static bool arg_recursive = true; static bool arg_recursive_unset = false; -static enum { - COUNT_PIDS, - COUNT_USERSPACE_PROCESSES, - COUNT_ALL_PROCESSES, -} arg_count = COUNT_PIDS; +static PidsCount arg_count = COUNT_PIDS; static enum { ORDER_PATH, @@ -916,6 +918,7 @@ static int run(int argc, char *argv[]) { usec_t last_refresh = 0; bool quit = false, immediate_refresh = false; _cleanup_free_ char *root = NULL; + PidsCount possible_count; CGroupMask mask; int r; @@ -929,7 +932,8 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to determine supported controllers: %m"); - arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES; + possible_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_ALL_PROCESSES; + arg_count = MIN(possible_count, arg_count); if (arg_recursive_unset && arg_count == COUNT_PIDS) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), |