cgls.c revision 13be49798cc4d1bdf84780b6a315e920f20fa11a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <string.h>
#include "cgroup-show.h"
#include "cgroup-util.h"
#include "log.h"
#include "path-util.h"
#include "util.h"
#include "pager.h"
#include "build.h"
#include "output-mode.h"
#include "fileio.h"
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "unit-name.h"
static bool arg_no_pager = false;
static bool arg_kernel_threads = false;
static bool arg_all = false;
static int arg_full = -1;
static char* arg_machine = NULL;
static int help(void) {
printf("%s [OPTIONS...] [CGROUP...]\n\n"
"Recursively show control group contents.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
" -a --all Show all groups, including empty\n"
" -l --full Do not ellipsize output\n"
" -k Include kernel threads in output\n"
" -M --machine Show container\n",
return 0;
}
enum {
ARG_NO_PAGER = 0x100,
};
{}
};
int c;
switch (c) {
case 'h':
return help();
case ARG_VERSION:
return 0;
case ARG_NO_PAGER:
arg_no_pager = true;
break;
case 'a':
arg_all = true;
break;
case 'l':
arg_full = true;
break;
case 'k':
arg_kernel_threads = true;
break;
case 'M':
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
}
return 1;
}
int r = 0, retval = EXIT_FAILURE;
int output_flags;
log_open();
if (r < 0)
goto finish;
else if (r == 0) {
goto finish;
}
if (!arg_no_pager) {
r = pager_open(false);
if (r > 0) {
if (arg_full == -1)
arg_full = true;
}
}
(arg_full > 0) * OUTPUT_FULL_WIDTH;
if (r < 0) {
goto finish;
}
int i;
int q;
if (arg_machine)
else
if (!root)
return log_oom();
if (q < 0)
r = q;
}
} else {
_cleanup_free_ char *p;
p = get_current_dir_name();
if (!p) {
log_error("Cannot determine current working directory: %m");
goto finish;
}
printf("Working Directory %s:\n", p);
r = show_cgroup_by_path(p, NULL, 0,
} else {
if (arg_machine) {
char *m;
const char *cgroup;
if (r < 0) {
goto finish;
}
if (!path) {
r = log_oom();
goto finish;
}
r = sd_bus_get_property(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Scope",
"ControlGroup",
&error,
&reply,
"s");
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (!root) {
r = log_oom();
goto finish;
}
} else
r = cg_get_root_path(&root);
if (r < 0) {
log_error("Failed to get %s path: %s",
goto finish;
}
}
}
if (r < 0) {
} else
pager_close();
return retval;
}