mirror of
https://github.com/systemd/systemd.git
synced 2025-03-06 00:58:29 +03:00
cgls: enable cgroupid/xattr output by default (but make it configurable)
This commit is contained in:
parent
5a5a5d2914
commit
87843de48b
@ -16,6 +16,7 @@
|
|||||||
#include "main-func.h"
|
#include "main-func.h"
|
||||||
#include "output-mode.h"
|
#include "output-mode.h"
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
|
#include "parse-util.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "pretty-print.h"
|
#include "pretty-print.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
@ -23,8 +24,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static PagerFlags arg_pager_flags = 0;
|
static PagerFlags arg_pager_flags = 0;
|
||||||
static bool arg_kernel_threads = false;
|
static OutputFlags arg_output_flags = OUTPUT_CGROUP_XATTRS | OUTPUT_CGROUP_ID;
|
||||||
static bool arg_all = false;
|
|
||||||
|
|
||||||
static enum {
|
static enum {
|
||||||
SHOW_UNIT_NONE,
|
SHOW_UNIT_NONE,
|
||||||
@ -54,6 +54,8 @@ static int help(void) {
|
|||||||
" -a --all Show all groups, including empty\n"
|
" -a --all Show all groups, including empty\n"
|
||||||
" -u --unit Show the subtrees of specified system units\n"
|
" -u --unit Show the subtrees of specified system units\n"
|
||||||
" --user-unit Show the subtrees of specified user 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"
|
" -l --full Do not ellipsize output\n"
|
||||||
" -k Include kernel threads in output\n"
|
" -k Include kernel threads in output\n"
|
||||||
" -M --machine= Show container\n"
|
" -M --machine= Show container\n"
|
||||||
@ -70,6 +72,8 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
ARG_NO_PAGER = 0x100,
|
ARG_NO_PAGER = 0x100,
|
||||||
ARG_VERSION,
|
ARG_VERSION,
|
||||||
ARG_USER_UNIT,
|
ARG_USER_UNIT,
|
||||||
|
ARG_XATTR,
|
||||||
|
ARG_CGROUP_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
@ -81,10 +85,12 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
{ "machine", required_argument, NULL, 'M' },
|
{ "machine", required_argument, NULL, 'M' },
|
||||||
{ "unit", optional_argument, NULL, 'u' },
|
{ "unit", optional_argument, NULL, 'u' },
|
||||||
{ "user-unit", optional_argument, NULL, ARG_USER_UNIT },
|
{ "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(argc >= 1);
|
||||||
assert(argv);
|
assert(argv);
|
||||||
@ -104,7 +110,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
arg_all = true;
|
arg_output_flags |= OUTPUT_SHOW_ALL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
@ -130,13 +136,29 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'k':
|
case 'k':
|
||||||
arg_kernel_threads = true;
|
arg_output_flags |= OUTPUT_KERNEL_THREADS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
arg_machine = optarg;
|
arg_machine = optarg;
|
||||||
break;
|
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 '?':
|
case '?':
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
@ -161,7 +183,7 @@ static void show_cg_info(const char *controller, const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int run(int argc, char *argv[]) {
|
static int run(int argc, char *argv[]) {
|
||||||
int r, output_flags;
|
int r;
|
||||||
|
|
||||||
log_setup();
|
log_setup();
|
||||||
|
|
||||||
@ -173,10 +195,8 @@ static int run(int argc, char *argv[]) {
|
|||||||
if (r > 0 && arg_full < 0)
|
if (r > 0 && arg_full < 0)
|
||||||
arg_full = true;
|
arg_full = true;
|
||||||
|
|
||||||
output_flags =
|
if (arg_full > 0)
|
||||||
arg_all * OUTPUT_SHOW_ALL |
|
arg_output_flags |= OUTPUT_FULL_WIDTH;
|
||||||
(arg_full > 0) * OUTPUT_FULL_WIDTH |
|
|
||||||
arg_kernel_threads * OUTPUT_KERNEL_THREADS;
|
|
||||||
|
|
||||||
if (arg_names) {
|
if (arg_names) {
|
||||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||||
@ -204,22 +224,21 @@ static int run(int argc, char *argv[]) {
|
|||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
if (isempty(cgroup)) {
|
if (isempty(cgroup)) {
|
||||||
log_warning("Unit %s not found.", *name);
|
q = log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Unit %s not found.", *name);
|
||||||
q = -ENOENT;
|
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Unit %s (%s):\n", *name, cgroup);
|
printf("Unit %s (%s):\n", *name, cgroup);
|
||||||
fflush(stdout);
|
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")) {
|
} else if (path_startswith(*name, "/sys/fs/cgroup")) {
|
||||||
|
|
||||||
printf("Directory %s:\n", *name);
|
printf("Directory %s:\n", *name);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
q = show_cgroup_by_path(*name, NULL, 0, output_flags);
|
q = show_cgroup_by_path(*name, NULL, 0, arg_output_flags);
|
||||||
} else {
|
} else {
|
||||||
_cleanup_free_ char *c = NULL, *p = NULL, *j = NULL;
|
_cleanup_free_ char *c = NULL, *p = NULL, *j = NULL;
|
||||||
const char *controller, *path;
|
const char *controller, *path;
|
||||||
@ -250,7 +269,7 @@ static int run(int argc, char *argv[]) {
|
|||||||
|
|
||||||
show_cg_info(controller, path);
|
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:
|
failed:
|
||||||
@ -272,7 +291,7 @@ static int run(int argc, char *argv[]) {
|
|||||||
printf("Working directory %s:\n", cwd);
|
printf("Working directory %s:\n", cwd);
|
||||||
fflush(stdout);
|
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;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,7 +306,7 @@ static int run(int argc, char *argv[]) {
|
|||||||
show_cg_info(SYSTEMD_CGROUP_CONTROLLER, root);
|
show_cg_info(SYSTEMD_CGROUP_CONTROLLER, root);
|
||||||
|
|
||||||
printf("-.slice\n");
|
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)
|
if (r < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user