summaryrefslogtreecommitdiff
path: root/src/cgtop
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-04-24 19:28:05 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-04-25 08:54:00 -0400
commit6d9f40d5db71eb3227898e1a58fee36d9c76d450 (patch)
tree137dbe185e2e499ea51808d2134e1c81e0fc195c /src/cgtop
parentcaf222104afe2d12f3a188a6bfee3a35f2d04fc6 (diff)
downloadsystemd-6d9f40d5db71eb3227898e1a58fee36d9c76d450.tar.gz
cgtop: check cgroups after parsing options
We would try to determine controllers even if not necessary: <mock-chroot><mock-chroot> sh-4.4# ./systemd-cgtop --help Failed to determine supported controllers: No medium found <mock-chroot><mock-chroot> sh-4.4# ./systemd-cgtop --version Failed to determine supported controllers: No medium found This broke check-help-systemd-cgtop under mock, but even apart from that, the program should be able to print --version in any circumstances.
Diffstat (limited to 'src/cgtop')
-rw-r--r--src/cgtop/cgtop.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 67f3a99860..7ebb02fa8c 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -75,6 +75,7 @@ static usec_t arg_delay = 1*USEC_PER_SEC;
static char* arg_machine = NULL;
static char* arg_root = NULL;
static bool arg_recursive = true;
+static bool arg_recursive_unset = false;
static enum {
COUNT_PIDS,
@@ -732,7 +733,6 @@ static int parse_argv(int argc, char *argv[]) {
{}
};
- bool recursive_unset = false;
int c, r;
assert(argc >= 1);
@@ -852,7 +852,7 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_recursive = r;
- recursive_unset = r == 0;
+ arg_recursive_unset = r == 0;
break;
case 'M':
@@ -873,11 +873,6 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- if (recursive_unset && arg_count == COUNT_PIDS) {
- log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
- return -EINVAL;
- }
-
return 1;
}
@@ -902,6 +897,10 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
+ r = parse_argv(argc, argv);
+ if (r <= 0)
+ goto finish;
+
r = cg_mask_supported(&mask);
if (r < 0) {
log_error_errno(r, "Failed to determine supported controllers: %m");
@@ -910,9 +909,10 @@ int main(int argc, char *argv[]) {
arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES;
- r = parse_argv(argc, argv);
- if (r <= 0)
- goto finish;
+ if (arg_recursive_unset && arg_count == COUNT_PIDS) {
+ log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
+ return -EINVAL;
+ }
r = show_cgroup_get_path_and_warn(arg_machine, arg_root, &root);
if (r < 0) {