summaryrefslogtreecommitdiffstats
path: root/src/cgls
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-06 17:07:43 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-07 11:50:47 +0200
commit87843de48bf2a5425ede1ff8aa9e16aff0214170 (patch)
treea822ec2396692c33906446860827a415024f58bc /src/cgls
parentcgroups-show: optionally show cgroup xattrs + cgroup id in cgroup tree output (diff)
downloadsystemd-87843de48bf2a5425ede1ff8aa9e16aff0214170.tar.xz
systemd-87843de48bf2a5425ede1ff8aa9e16aff0214170.zip
cgls: enable cgroupid/xattr output by default (but make it configurable)
Diffstat (limited to 'src/cgls')
-rw-r--r--src/cgls/cgls.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c
index ab5f153d9d..e2c746f7e7 100644
--- a/src/cgls/cgls.c
+++ b/src/cgls/cgls.c
@@ -16,6 +16,7 @@
#include "main-func.h"
#include "output-mode.h"
#include "pager.h"
+#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
#include "strv.h"
@@ -23,8 +24,7 @@
#include "util.h"
static PagerFlags arg_pager_flags = 0;
-static bool arg_kernel_threads = false;
-static bool arg_all = false;
+static OutputFlags arg_output_flags = OUTPUT_CGROUP_XATTRS | OUTPUT_CGROUP_ID;
static enum {
SHOW_UNIT_NONE,
@@ -54,6 +54,8 @@ static int help(void) {
" -a --all Show all groups, including empty\n"
" -u --unit Show the subtrees of specified system units\n"
" --user-unit Show the subtrees of specified user units\n"
+ " --xattr=BOOL Show cgroup extended attributes\n"
+ " --cgroup-id=BOOL Show cgroup ID\n"
" -l --full Do not ellipsize output\n"
" -k Include kernel threads in output\n"
" -M --machine= Show container\n"
@@ -70,6 +72,8 @@ static int parse_argv(int argc, char *argv[]) {
ARG_NO_PAGER = 0x100,
ARG_VERSION,
ARG_USER_UNIT,
+ ARG_XATTR,
+ ARG_CGROUP_ID,
};
static const struct option options[] = {
@@ -81,10 +85,12 @@ static int parse_argv(int argc, char *argv[]) {
{ "machine", required_argument, NULL, 'M' },
{ "unit", optional_argument, NULL, 'u' },
{ "user-unit", optional_argument, NULL, ARG_USER_UNIT },
+ { "xattr", required_argument, NULL, ARG_XATTR },
+ { "cgroup-id", required_argument, NULL, ARG_CGROUP_ID },
{}
};
- int c;
+ int c, r;
assert(argc >= 1);
assert(argv);
@@ -104,7 +110,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'a':
- arg_all = true;
+ arg_output_flags |= OUTPUT_SHOW_ALL;
break;
case 'u':
@@ -130,13 +136,29 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'k':
- arg_kernel_threads = true;
+ arg_output_flags |= OUTPUT_KERNEL_THREADS;
break;
case 'M':
arg_machine = optarg;
break;
+ case ARG_XATTR:
+ r = parse_boolean(optarg);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse --xattr= value: %s", optarg);
+
+ SET_FLAG(arg_output_flags, OUTPUT_CGROUP_XATTRS, r);
+ break;
+
+ case ARG_CGROUP_ID:
+ r = parse_boolean(optarg);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse --cgroup-id= value: %s", optarg);
+
+ SET_FLAG(arg_output_flags, OUTPUT_CGROUP_ID, r);
+ break;
+
case '?':
return -EINVAL;
@@ -161,7 +183,7 @@ static void show_cg_info(const char *controller, const char *path) {
}
static int run(int argc, char *argv[]) {
- int r, output_flags;
+ int r;
log_setup();
@@ -173,10 +195,8 @@ static int run(int argc, char *argv[]) {
if (r > 0 && arg_full < 0)
arg_full = true;
- output_flags =
- arg_all * OUTPUT_SHOW_ALL |
- (arg_full > 0) * OUTPUT_FULL_WIDTH |
- arg_kernel_threads * OUTPUT_KERNEL_THREADS;
+ if (arg_full > 0)
+ arg_output_flags |= OUTPUT_FULL_WIDTH;
if (arg_names) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
@@ -204,22 +224,21 @@ static int run(int argc, char *argv[]) {
goto failed;
if (isempty(cgroup)) {
- log_warning("Unit %s not found.", *name);
- q = -ENOENT;
+ q = log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Unit %s not found.", *name);
goto failed;
}
printf("Unit %s (%s):\n", *name, cgroup);
fflush(stdout);
- q = show_cgroup_by_path(cgroup, NULL, 0, output_flags);
+ q = show_cgroup_by_path(cgroup, NULL, 0, arg_output_flags);
} else if (path_startswith(*name, "/sys/fs/cgroup")) {
printf("Directory %s:\n", *name);
fflush(stdout);
- q = show_cgroup_by_path(*name, NULL, 0, output_flags);
+ q = show_cgroup_by_path(*name, NULL, 0, arg_output_flags);
} else {
_cleanup_free_ char *c = NULL, *p = NULL, *j = NULL;
const char *controller, *path;
@@ -250,7 +269,7 @@ static int run(int argc, char *argv[]) {
show_cg_info(controller, path);
- q = show_cgroup(controller, path, NULL, 0, output_flags);
+ q = show_cgroup(controller, path, NULL, 0, arg_output_flags);
}
failed:
@@ -272,7 +291,7 @@ static int run(int argc, char *argv[]) {
printf("Working directory %s:\n", cwd);
fflush(stdout);
- r = show_cgroup_by_path(cwd, NULL, 0, output_flags);
+ r = show_cgroup_by_path(cwd, NULL, 0, arg_output_flags);
done = true;
}
}
@@ -287,7 +306,7 @@ static int run(int argc, char *argv[]) {
show_cg_info(SYSTEMD_CGROUP_CONTROLLER, root);
printf("-.slice\n");
- r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, root, NULL, 0, output_flags);
+ r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, root, NULL, 0, arg_output_flags);
}
}
if (r < 0)