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 General Public License as published by
10 the Free Software Foundation; either version 2 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 General Public License for more details.
18 You should have received a copy of the GNU 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;
37 static void help(void) {
39 printf("%s [OPTIONS...] [CGROUP...]\n\n"
40 "Recursively show control group contents.\n\n"
41 " -h --help Show this help\n"
42 " --no-pager Do not pipe output into a pager\n",
43 program_invocation_short_name);
46 static int parse_argv(int argc, char *argv[]) {
52 static const struct option options[] = {
53 { "help", no_argument, NULL, 'h' },
54 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
63 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
79 log_error("Unknown option code %c", c);
87 int main(int argc, char *argv[]) {
88 int r = 0, retval = EXIT_FAILURE;
90 log_parse_environment();
93 if ((r = parse_argv(argc, argv)) < 0)
96 retval = EXIT_SUCCESS;
106 for (i = (unsigned) optind; i < (unsigned) argc; i++) {
108 printf("%s:\n", argv[i]);
110 if ((q = show_cgroup_by_path(argv[i], NULL, 0)) < 0)
117 if (!(p = get_current_dir_name())) {
118 log_error("Cannot determine current working directory: %m");
122 if (path_startswith(p, "/sys/fs/cgroup")) {
123 printf("Working Directory %s:\n", p);
124 r = show_cgroup_by_path(p, NULL, 0);
127 const char *t = NULL;
129 if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &root)) < 0)
132 if (endswith(root, "/system"))
133 root[strlen(root)-7] = 0;
135 t = root[0] ? root : "/";
138 r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, t, NULL, 0);
146 log_error("Failed to list cgroup tree: %s", strerror(-r));
148 retval = EXIT_SUCCESS;