cgls.c revision c33b329709ebe2755181980a050d02ec7c81ed87
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering This file is part of systemd.
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering Copyright 2010 Lennart Poettering
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering systemd is free software; you can redistribute it and/or modify it
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering under the terms of the GNU Lesser General Public License as published by
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering (at your option) any later version.
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering systemd is distributed in the hope that it will be useful, but
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Lesser General Public License for more details.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering You should have received a copy of the GNU Lesser General Public License
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poetteringstatic bool arg_no_pager = false;
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poetteringstatic bool arg_kernel_threads = false;
95ea1b90cc61f464f3b9bc147119dee4ba9620b8Lennart Poetteringstatic bool arg_all = false;
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poetteringstatic void help(void) {
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering "Recursively show control group contents.\n\n"
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering " -h --help Show this help\n"
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering " --version Show package version\n"
c2373f848dddcc1827cf715c5ef778dc8d475761Lennart Poettering " --no-pager Do not pipe output into a pager\n"
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering " -a --all Show all groups, including empty\n"
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering " -l --full Do not ellipsize output\n"
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering " -k Include kernel threads in output\n"
c2373f848dddcc1827cf715c5ef778dc8d475761Lennart Poettering " -M --machine Show container\n"
c2373f848dddcc1827cf715c5ef778dc8d475761Lennart Poetteringstatic int parse_argv(int argc, char *argv[]) {
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering { "version", no_argument, NULL, ARG_VERSION },
de190aef08bb267b645205a747762df573b36834Lennart Poettering { "no-pager", no_argument, NULL, ARG_NO_PAGER },
de190aef08bb267b645205a747762df573b36834Lennart Poettering { "machine", required_argument, NULL, 'M' },
87d2c1ff6a7375f03476767e6f59454bcc5cd04bLennart Poettering while ((c = getopt_long(argc, argv, "hkalM:", options, NULL)) >= 0)
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmekint main(int argc, char *argv[]) {
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek int r = 0, retval = EXIT_FAILURE;
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek _cleanup_free_ char *root = NULL;
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek _cleanup_bus_close_unref_ sd_bus *bus = NULL;
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek else if (r == 0) {
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek (arg_full > 0) * OUTPUT_FULL_WIDTH;
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek r = bus_open_transport(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to create bus connection: %m");
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek for (i = optind; i < argc; i++) {
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek fprintf(stdout, "%s:\n", argv[i]);
6eb7a9a0010d035e5bdbbf70227088ce02b2120eZbigniew Jędrzejewski-Szmek root = strjoin("machine/", arg_machine, "/", argv[i], NULL);
143bfdaf0b890fa7acadf02d1eafacaef1b696bdHolger Hans Peter Freyther q = show_cgroup_by_path(root, NULL, 0,
143bfdaf0b890fa7acadf02d1eafacaef1b696bdHolger Hans Peter Freyther arg_kernel_threads, output_flags);
p = get_current_dir_name();
goto finish;
if (arg_machine) {
const char *cgroup;
goto finish;
if (!path) {
log_oom();
goto finish;
r = sd_bus_get_property(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Scope",
&error,
&reply,
goto finish;
goto finish;
if (!root) {
log_oom();
goto finish;
goto finish;
pager_close();
return retval;