cgls.c revision 422fa6500a44a222b655cd218a658f8a4f34a768
/*-*- 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"
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 void 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",
}
enum {
ARG_NO_PAGER = 0x100,
};
};
int c;
switch (c) {
case 'h':
help();
return 0;
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:
log_error("Unknown option code %c", c);
return -EINVAL;
}
}
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;
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)
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;
}