diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-16 10:28:36 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-17 09:03:54 +0100 |
commit | a974a6569e31665717661dbf223e5ab36a515fb8 (patch) | |
tree | d74471aa02a8ffa8356684537aecd2d7c1cd6469 /src/cgtop/cgtop.c | |
parent | update TODO (diff) | |
download | systemd-a974a6569e31665717661dbf223e5ab36a515fb8.tar.xz systemd-a974a6569e31665717661dbf223e5ab36a515fb8.zip |
Introduce main definer and use it in cgtop
This actually fixes one bogus return code in error path.
Diffstat (limited to 'src/cgtop/cgtop.c')
-rw-r--r-- | src/cgtop/cgtop.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index efbfd240a6..8c0c46e3dd 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -733,7 +733,6 @@ static int help(void) { } static int parse_argv(int argc, char *argv[]) { - enum { ARG_VERSION = 0x100, ARG_DEPTH, @@ -908,7 +907,7 @@ static const char* counting_what(void) { return "userspace processes (excl. kernel)"; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { _cleanup_(group_hashmap_freep) Hashmap *a = NULL, *b = NULL; unsigned iteration = 0; usec_t last_refresh = 0; @@ -922,13 +921,11 @@ int main(int argc, char *argv[]) { r = parse_argv(argc, argv); if (r <= 0) - goto finish; + return r; r = cg_mask_supported(&mask); - if (r < 0) { - log_error_errno(r, "Failed to determine supported controllers: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to determine supported controllers: %m"); arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES; @@ -938,18 +935,14 @@ int main(int argc, char *argv[]) { } r = show_cgroup_get_path_and_warn(arg_machine, arg_root, &root); - if (r < 0) { - log_error_errno(r, "Failed to get root control group path: %m"); - goto finish; - } else - log_debug("Cgroup path: %s", root); + if (r < 0) + return log_error_errno(r, "Failed to get root control group path: %m"); + log_debug("Cgroup path: %s", root); a = hashmap_new(&path_hash_ops); b = hashmap_new(&path_hash_ops); - if (!a || !b) { - r = log_oom(); - goto finish; - } + if (!a || !b) + return log_oom(); signal(SIGWINCH, columns_lines_cache_reset); @@ -967,10 +960,8 @@ int main(int argc, char *argv[]) { if (t >= last_refresh + arg_delay || immediate_refresh) { r = refresh(root, a, b, iteration++); - if (r < 0) { - log_error_errno(r, "Failed to refresh: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to refresh: %m"); group_hashmap_clear(b); @@ -997,10 +988,8 @@ int main(int argc, char *argv[]) { r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL); if (r == -ETIMEDOUT) continue; - if (r < 0) { - log_error_errno(r, "Couldn't read key: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Couldn't read key: %m"); } if (on_tty()) { /* TTY: Clear any user keystroke */ @@ -1120,9 +1109,7 @@ int main(int argc, char *argv[]) { } } - r = 0; - -finish: - - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return 0; } + +DEFINE_MAIN_FUNCTION(run); |