1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include "cgroup-show.h"
30 #include "cgroup-util.h"
35 static bool arg_no_pager = false;
36 static bool arg_kernel_threads = false;
38 static void help(void) {
40 printf("%s [OPTIONS...] [CGROUP...]\n\n"
41 "Recursively show control group contents.\n\n"
42 " -h --help Show this help\n"
43 " --no-pager Do not pipe output into a pager\n"
44 " -k Include kernel threads in output\n",
45 program_invocation_short_name);
48 static int parse_argv(int argc, char *argv[]) {
54 static const struct option options[] = {
55 { "help", no_argument, NULL, 'h' },
56 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
65 while ((c = getopt_long(argc, argv, "hk", options, NULL)) >= 0) {
78 arg_kernel_threads = true;
85 log_error("Unknown option code %c", c);
93 int main(int argc, char *argv[]) {
94 int r = 0, retval = EXIT_FAILURE;
96 log_parse_environment();
99 r = parse_argv(argc, argv);
103 retval = EXIT_SUCCESS;
113 for (i = (unsigned) optind; i < (unsigned) argc; i++) {
115 printf("%s:\n", argv[i]);
117 q = show_cgroup_by_path(argv[i], NULL, 0, arg_kernel_threads);
125 p = get_current_dir_name();
127 log_error("Cannot determine current working directory: %m");
131 if (path_startswith(p, "/sys/fs/cgroup")) {
132 printf("Working Directory %s:\n", p);
133 r = show_cgroup_by_path(p, NULL, 0, arg_kernel_threads);
136 const char *t = NULL;
138 r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &root);
142 if (endswith(root, "/system"))
143 root[strlen(root)-7] = 0;
145 t = root[0] ? root : "/";
148 r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, t, NULL, 0, arg_kernel_threads);
156 log_error("Failed to list cgroup tree: %s", strerror(-r));
158 retval = EXIT_SUCCESS;