]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgtop: command line parsing improvements
authorLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2018 15:59:27 +0000 (16:59 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2018 15:59:27 +0000 (16:59 +0100)
Always output the string we were unable to parse and use
log_error_errno()'s return logic to shorten our code a bit.

src/cgtop/cgtop.c

index 229aadd26982cd01068baff22ee73d8b73e8e9b3..4e406e4ad252b5e7efd6365be7814a7265b42021 100644 (file)
@@ -782,17 +782,15 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_DEPTH:
                         r = safe_atou(optarg, &arg_depth);
-                        if (r < 0) {
-                                log_error("Failed to parse depth parameter.");
-                                return -EINVAL;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse depth parameter: %s", optarg);
 
                         break;
 
                 case 'd':
                         r = parse_sec(optarg, &arg_delay);
                         if (r < 0 || arg_delay <= 0) {
-                                log_error("Failed to parse delay parameter.");
+                                log_error("Failed to parse delay parameter: %s", optarg);
                                 return -EINVAL;
                         }
 
@@ -800,10 +798,8 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case 'n':
                         r = safe_atou(optarg, &arg_iterations);
-                        if (r < 0) {
-                                log_error("Failed to parse iterations parameter.");
-                                return -EINVAL;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse iterations parameter: %s", optarg);
 
                         break;
 
@@ -866,10 +862,8 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_RECURSIVE:
                         r = parse_boolean(optarg);
-                        if (r < 0) {
-                                log_error("Failed to parse --recursive= argument: %s", optarg);
-                                return r;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse --recursive= argument: %s", optarg);
 
                         arg_recursive = r;
                         arg_recursive_unset = r == 0;