X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcgtop%2Fcgtop.c;h=ee421e383b2eec9e2314a006d79daee71033a32a;hp=d8d36b361922fbafd884aed21bcde3e7aabb7793;hb=28917d7dc711746795f7e6468c06c1983a5cdf53;hpb=11f96fac8f30423cb14f84622de9ed56b3b8f093 diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index d8d36b361..ee421e383 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -30,6 +30,7 @@ #include "util.h" #include "hashmap.h" #include "cgroup-util.h" +#include "build.h" typedef struct Group { char *path; @@ -299,7 +300,7 @@ static int refresh_one( r = cg_enumerate_subgroups(controller, path, &d); if (r < 0) { - if (r == ENOENT) + if (r == -ENOENT) return 0; return r; @@ -446,7 +447,7 @@ static int display(Hashmap *a) { if (rows <= 0) rows = 25; - path_columns = columns_uncached() - 42; + path_columns = columns() - 42; if (path_columns < 10) path_columns = 10; @@ -511,6 +512,7 @@ static void help(void) { printf("%s [OPTIONS...]\n\n" "Show top control groups by their resource usage.\n\n" " -h --help Show this help\n" + " --version Print version and exit\n" " -p Order by path\n" " -t Order by number of tasks\n" " -c Order by CPU load\n" @@ -523,19 +525,25 @@ static void help(void) { program_invocation_short_name); } +static void version(void) { + puts(PACKAGE_STRING " cgtop"); +} + static int parse_argv(int argc, char *argv[]) { enum { - ARG_DEPTH = 0x100 + ARG_VERSION = 0x100, + ARG_DEPTH, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "delay", required_argument, NULL, 'd' }, - { "iterations", required_argument, NULL, 'n' }, - { "batch", no_argument, NULL, 'b' }, - { "depth", required_argument, NULL, ARG_DEPTH }, - { NULL, 0, NULL, 0 } + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "delay", required_argument, NULL, 'd' }, + { "iterations", required_argument, NULL, 'n' }, + { "batch", no_argument, NULL, 'b' }, + { "depth", required_argument, NULL, ARG_DEPTH }, + { NULL, 0, NULL, 0 } }; int c; @@ -552,6 +560,10 @@ static int parse_argv(int argc, char *argv[]) { help(); return 0; + case ARG_VERSION: + version(); + return 0; + case ARG_DEPTH: r = safe_atou(optarg, &arg_depth); if (r < 0) { @@ -641,6 +653,8 @@ int main(int argc, char *argv[]) { goto finish; } + signal(SIGWINCH, columns_cache_reset); + while (!quit) { Hashmap *c; usec_t t; @@ -770,5 +784,10 @@ finish: group_hashmap_free(a); group_hashmap_free(b); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + if (r < 0) { + log_error("Exiting with failure: %s", strerror(-r)); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; }