X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcgtop%2Fcgtop.c;h=932a7ba7c6c360c8bf5d1c2ad8842d7f47e0c21b;hp=293a2113bdcbcc9510e34eeb4d0e262b0a6960af;hb=2d5c93c7af05bfa25cad85909acdb7b0bfc3f4e1;hpb=7ff7394d9e4e9189c30fd018235e6b1728c6f2d0 diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 293a2113b..932a7ba7c 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -98,7 +98,7 @@ static void group_hashmap_free(Hashmap *h) { static int process(const char *controller, const char *path, Hashmap *a, Hashmap *b, unsigned iteration) { Group *g; int r; - FILE *f; + FILE *f = NULL; pid_t pid; unsigned n; @@ -126,7 +126,9 @@ static int process(const char *controller, const char *path, Hashmap *a, Hashmap return r; } } else { - assert_se(hashmap_move_one(a, b, path) == 0); + r = hashmap_move_one(a, b, path); + if (r < 0) + return r; g->cpu_valid = g->memory_valid = g->io_valid = g->n_tasks_valid = false; } } @@ -549,7 +551,6 @@ static int display(Hashmap *a) { } 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" @@ -563,12 +564,8 @@ static void help(void) { " -d --delay=DELAY Delay between updates\n" " -n --iterations=N Run for N iterations before exiting\n" " -b --batch Run in batch mode, accepting no input\n" - " --depth=DEPTH Maximum traversal depth (default: %d)\n", - program_invocation_short_name, arg_depth); -} - -static void version(void) { - puts(PACKAGE_STRING " cgtop"); + " --depth=DEPTH Maximum traversal depth (default: %u)\n" + , program_invocation_short_name, arg_depth); } static int parse_argv(int argc, char *argv[]) { @@ -587,7 +584,7 @@ static int parse_argv(int argc, char *argv[]) { { "batch", no_argument, NULL, 'b' }, { "depth", required_argument, NULL, ARG_DEPTH }, { "cpu", optional_argument, NULL, ARG_CPU_TYPE}, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -596,7 +593,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 1); assert(argv); - while ((c = getopt_long(argc, argv, "hptcmin:bd:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hptcmin:bd:", options, NULL)) >= 0) switch (c) { @@ -605,7 +602,8 @@ static int parse_argv(int argc, char *argv[]) { return 0; case ARG_VERSION: - version(); + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case ARG_CPU_TYPE: @@ -674,10 +672,8 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } - } if (optind < argc) { log_error("Too many arguments."); @@ -701,8 +697,8 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - a = hashmap_new(string_hash_func, string_compare_func); - b = hashmap_new(string_hash_func, string_compare_func); + a = hashmap_new(&string_hash_ops); + b = hashmap_new(&string_hash_ops); if (!a || !b) { r = log_oom(); goto finish;