1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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"
34 static void help(void) {
36 printf("%s [OPTIONS...] [CGROUP...]\n\n"
37 "Recursively show control group contents.\n\n"
38 " -h --help Show this help\n",
39 program_invocation_short_name);
42 static int parse_argv(int argc, char *argv[]) {
44 static const struct option options[] = {
45 { "help", no_argument, NULL, 'h' },
54 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
66 log_error("Unknown option code %c", c);
74 int main(int argc, char *argv[]) {
75 int r = 0, retval = 1;
77 log_parse_environment();
79 if ((r = parse_argv(argc, argv)) < 0)
89 for (i = (unsigned) optind; i < (unsigned) argc; i++) {
91 printf("%s:\n", argv[i]);
93 if ((q = show_cgroup_by_path(argv[i], NULL, 0)) < 0)
100 if (!(p = get_current_dir_name())) {
101 log_error("Cannot determine current working directory: %m");
105 if (path_startswith(p, "/cgroup")) {
106 printf("Working Directory %s:\n", p);
107 r = show_cgroup_by_path(p, NULL, 0);
109 r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, "/", NULL, 0);
115 log_error("Failed to list cgroup tree: %s", strerror(-r));