cg_get_machine_path is modified to include the escaped machine name
+ ".nspawn" if the machine argument is nonnull.
<refsynopsisdiv>
<cmdsynopsis>
<refsynopsisdiv>
<cmdsynopsis>
- <command>systemd-cgls <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">CGROUP</arg></command>
+ <command>systemd-cgls</command>
+ <arg choice="opt" rep="repeat">OPTIONS</arg>
+ <arg choice="opt" rep="repeat">CGROUP</arg>
</cmdsynopsis>
</refsynopsisdiv>
</cmdsynopsis>
</refsynopsisdiv>
threads in output.</para></listitem>
</varlistentry>
threads in output.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-m <replaceable>MACHINE</replaceable></option></term>
+ <term><option>--machine=<replaceable>MACHINE</replaceable></option></term>
+
+ <listitem><para>Limit cgroups shown to
+ the part corresponding to the
+ container <replaceable>MACHINE</replaceable>.
+ </para></listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
</variablelist>
</refsect1>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-cgtop</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd-cgtop</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>
</refsect1>
<citerefentry><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>
</refsect1>
}
static int list_dependencies(DBusConnection *bus) {
}
static int list_dependencies(DBusConnection *bus) {
- _cleanup_free_ char *unit = NULL;
_cleanup_strv_free_ char **units = NULL;
char ts[FORMAT_TIMESPAN_MAX];
struct unit_times *times;
_cleanup_strv_free_ char **units = NULL;
char ts[FORMAT_TIMESPAN_MAX];
struct unit_times *times;
static bool arg_kernel_threads = false;
static bool arg_all = false;
static int arg_full = -1;
static bool arg_kernel_threads = false;
static bool arg_all = false;
static int arg_full = -1;
+static char* arg_machine = NULL;
" --no-pager Do not pipe output into a pager\n"
" -a --all Show all groups, including empty\n"
" --full Do not ellipsize output\n"
" --no-pager Do not pipe output into a pager\n"
" -a --all Show all groups, including empty\n"
" --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",
program_invocation_short_name);
}
program_invocation_short_name);
}
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "all", no_argument, NULL, 'a' },
{ "full", no_argument, NULL, ARG_FULL },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "all", no_argument, NULL, 'a' },
{ "full", no_argument, NULL, ARG_FULL },
+ { "machine", required_argument, NULL, 'M' },
assert(argc >= 1);
assert(argv);
assert(argc >= 1);
assert(argv);
- while ((c = getopt_long(argc, argv, "hka", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hkaM:", options, NULL)) >= 0) {
arg_kernel_threads = true;
break;
arg_kernel_threads = true;
break;
+ case 'M':
+ arg_machine = optarg;
+ break;
+
case '?':
return -EINVAL;
case '?':
return -EINVAL;
int main(int argc, char *argv[]) {
int r = 0, retval = EXIT_FAILURE;
int output_flags;
int main(int argc, char *argv[]) {
int r = 0, retval = EXIT_FAILURE;
int output_flags;
+ char _cleanup_free_ *root = NULL;
log_parse_environment();
log_open();
log_parse_environment();
log_open();
(arg_full > 0) * OUTPUT_FULL_WIDTH;
if (optind < argc) {
(arg_full > 0) * OUTPUT_FULL_WIDTH;
if (optind < argc) {
- for (i = (unsigned) optind; i < (unsigned) argc; i++) {
+ for (i = optind; i < argc; i++) {
int q;
printf("%s:\n", argv[i]);
int q;
printf("%s:\n", argv[i]);
- q = show_cgroup_by_path(argv[i], NULL, 0,
+ if (arg_machine)
+ root = strjoin("machine/", arg_machine, "/", argv[i], NULL);
+ else
+ root = strdup(argv[i]);
+ if (!root)
+ return log_oom();
+
+ q = show_cgroup_by_path(root, NULL, 0,
arg_kernel_threads, output_flags);
if (q < 0)
r = q;
arg_kernel_threads, output_flags);
if (q < 0)
r = q;
- if (path_startswith(p, "/sys/fs/cgroup")) {
+ if (path_startswith(p, "/sys/fs/cgroup") && !arg_machine) {
printf("Working Directory %s:\n", p);
r = show_cgroup_by_path(p, NULL, 0,
arg_kernel_threads, output_flags);
} else {
printf("Working Directory %s:\n", p);
r = show_cgroup_by_path(p, NULL, 0,
arg_kernel_threads, output_flags);
} else {
- _cleanup_free_ char *root = NULL;
-
- r = cg_get_root_path(&root);
+ if (arg_machine)
+ r = cg_get_machine_path(arg_machine, &root);
+ else
+ r = cg_get_root_path(&root);
- log_error("Failed to get root path: %s", strerror(-r));
+ log_error("Failed to get %s path: %s",
+ arg_machine ? "machine" : "root", strerror(-r));
- if (r < 0)
- log_error("Failed to list cgroup tree: %s", strerror(-r));
-
- retval = EXIT_SUCCESS;
+ if (r < 0) {
+ log_error("Failed to list cgroup tree %s: %s", root, strerror(-r));
+ retval = EXIT_FAILURE;
+ } else
+ retval = EXIT_SUCCESS;
- r = cg_get_machine_path(&md);
+ r = cg_get_machine_path(NULL, &md);
_cleanup_free_ char *md = NULL, *p = NULL;
int r;
_cleanup_free_ char *md = NULL, *p = NULL;
int r;
- r = cg_get_machine_path(&md);
+ r = cg_get_machine_path(NULL, &md);
int main(int argc, char *argv[]) {
pid_t pid = 0;
int r = EXIT_FAILURE, k;
int main(int argc, char *argv[]) {
pid_t pid = 0;
int r = EXIT_FAILURE, k;
- _cleanup_free_ char *machine_root = NULL, *name = NULL, *escaped = NULL, *newcg = NULL;
+ _cleanup_free_ char *newcg = NULL;
_cleanup_close_ int master = -1;
int n_fd_passed;
const char *console = NULL;
_cleanup_close_ int master = -1;
int n_fd_passed;
const char *console = NULL;
fdset_close_others(fds);
log_open();
fdset_close_others(fds);
log_open();
- k = cg_get_machine_path(&machine_root);
+ k = cg_get_machine_path(arg_machine, &newcg);
if (k < 0) {
log_error("Failed to determine machine cgroup path: %s", strerror(-k));
goto finish;
}
if (k < 0) {
log_error("Failed to determine machine cgroup path: %s", strerror(-k));
goto finish;
}
- name = strappend(arg_machine, ".nspawn");
- if (!name) {
- log_oom();
- goto finish;
- }
-
- escaped = cg_escape(name);
- if (!escaped) {
- log_oom();
- goto finish;
- }
-
- newcg = strjoin(machine_root, "/", escaped, NULL);
- if (!newcg) {
- log_oom();
- goto finish;
- }
-
k = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, newcg, true);
if (k <= 0 && k != -ENOENT) {
log_error("Container already running.");
k = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, newcg, true);
if (k <= 0 && k != -ENOENT) {
log_error("Container already running.");
-int cg_get_machine_path(char **path) {
- _cleanup_free_ char *root = NULL;
+int cg_get_machine_path(const char *machine, char **path) {
+ _cleanup_free_ char *root = NULL, *escaped = NULL;
- if (cg_get_root_path(&root) < 0 || streq(root, "/"))
- p = strdup("/machine");
- else
- p = strappend(root, "/machine");
+ if (machine) {
+ const char *name = strappenda(machine, ".nspawn");
+
+ escaped = cg_escape(name);
+ if (!escaped)
+ return -ENOMEM;
+ }
+ p = strjoin(cg_get_root_path(&root) >= 0 && !streq(root, "/") ? root : "",
+ "/machine", machine ? "/" : "", machine ? escaped : "", NULL);
int cg_get_root_path(char **path);
int cg_get_system_path(char **path);
int cg_get_user_path(char **path);
int cg_get_root_path(char **path);
int cg_get_system_path(char **path);
int cg_get_user_path(char **path);
-int cg_get_machine_path(char **path);
+int cg_get_machine_path(const char *machine, char **path);
int cg_path_get_session(const char *path, char **session);
int cg_path_get_owner_uid(const char *path, uid_t *uid);
int cg_path_get_session(const char *path, char **session);
int cg_path_get_owner_uid(const char *path, uid_t *uid);
assert_se(cg_get_user_path(&c) >= 0);
log_info("User = %s", c);
assert_se(cg_get_user_path(&c) >= 0);
log_info("User = %s", c);
- assert_se(cg_get_machine_path(&d) >= 0);
+ assert_se(cg_get_machine_path("harley", &d) >= 0);
log_info("Machine = %s", d);
}
log_info("Machine = %s", d);
}