summaryrefslogtreecommitdiffstats
path: root/src/analyze/analyze.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-15 19:32:42 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-17 21:06:31 +0100
commit599c7c545f689f7d19a73238eecc69bf94fa6a74 (patch)
tree3d7cc8218ea1771ada8c36d094cda46a51c81291 /src/analyze/analyze.c
parentMerge pull request #18593 from keszybz/fuzz-more-systemctl-paths (diff)
downloadsystemd-599c7c545f689f7d19a73238eecc69bf94fa6a74.tar.xz
systemd-599c7c545f689f7d19a73238eecc69bf94fa6a74.zip
tree-wide: add a helper to parse boolean optarg
This nicely covers the case when optarg is optional. The same parser can be used when the option string passed to getopt_long() requires a parameter and when it doesn't. The error messages are made consistent. Also fixes a log error c&p in --crash-reboot message.
Diffstat (limited to 'src/analyze/analyze.c')
-rw-r--r--src/analyze/analyze.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index c25d11e0de..55d32fee22 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -37,6 +37,7 @@
#include "main-func.h"
#include "nulstr-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
@@ -2346,29 +2347,15 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_MAN:
- if (optarg) {
- r = parse_boolean(optarg);
- if (r < 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse --man= argument.");
-
- arg_man = r;
- } else
- arg_man = true;
-
+ r = parse_boolean_argument("--man", optarg, &arg_man);
+ if (r < 0)
+ return r;
break;
case ARG_GENERATORS:
- if (optarg) {
- r = parse_boolean(optarg);
- if (r < 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse --generators= argument.");
-
- arg_generators = r;
- } else
- arg_generators = true;
-
+ r = parse_boolean_argument("--generators", optarg, &arg_generators);
+ if (r < 0)
+ return r;
break;
case ARG_ITERATIONS: