summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/activate/activate.c12
-rw-r--r--src/analyze/analyze.c11
-rw-r--r--src/ask-password/ask-password.c22
-rw-r--r--src/binfmt/binfmt.c15
-rw-r--r--src/boot/bootctl.c33
-rw-r--r--src/bootchart/bootchart.c32
-rw-r--r--src/bus-proxyd/bus-proxyd.c3
-rw-r--r--src/cgls/cgls.c15
-rw-r--r--src/cgtop/cgtop.c15
-rw-r--r--src/core/main.c10
-rw-r--r--src/core/shutdown.c9
-rw-r--r--src/delta/delta.c12
-rw-r--r--src/detect-virt/detect-virt.c18
-rw-r--r--src/escape/escape.c15
-rw-r--r--src/firstboot/firstboot.c15
-rw-r--r--src/hostname/hostnamectl.c15
-rw-r--r--src/journal-remote/journal-gatewayd.c8
-rw-r--r--src/journal-remote/journal-remote.c3
-rw-r--r--src/journal/cat.c15
-rw-r--r--src/journal/coredumpctl.c46
-rw-r--r--src/journal/journalctl.c10
-rw-r--r--src/libsystemd/sd-bus/busctl.c8
-rw-r--r--src/locale/localectl.c15
-rw-r--r--src/login/inhibit.c15
-rw-r--r--src/login/loginctl.c15
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c11
-rw-r--r--src/machine/machinectl.c11
-rw-r--r--src/modules-load/modules-load.c11
-rw-r--r--src/network/networkd-wait-online.c15
-rw-r--r--src/notify/notify.c11
-rw-r--r--src/nspawn/nspawn.c11
-rw-r--r--src/path/path.c27
-rw-r--r--src/readahead/readahead.c30
-rw-r--r--src/resolve-host/resolve-host.c3
-rw-r--r--src/run/run.c11
-rw-r--r--src/sleep/sleep.c13
-rw-r--r--src/socket-proxy/socket-proxyd.c16
-rw-r--r--src/sysctl/sysctl.c15
-rw-r--r--src/systemctl/systemctl.c57
-rw-r--r--src/sysusers/sysusers.c15
-rw-r--r--src/test/test-libudev.c22
-rw-r--r--src/timedate/timedatectl.c11
-rw-r--r--src/tmpfiles/tmpfiles.c11
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c13
-rw-r--r--src/udev/udevadm.c23
45 files changed, 298 insertions, 426 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c
index c3309a8485..8942773866 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -279,7 +279,7 @@ static int install_chld_handler(void) {
return r;
}
-static int help(void) {
+static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Listen on sockets and launch child on connection.\n\n"
"Options:\n"
@@ -290,10 +290,7 @@ static int help(void) {
" --version Print version string and exit\n"
"\n"
"Note: file descriptors from sd_listen_fds() will be passed through.\n"
- , program_invocation_short_name
- );
-
- return 0;
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -319,7 +316,8 @@ static int parse_argv(int argc, char *argv[]) {
while ((c = getopt_long(argc, argv, "+hl:aE:", options, NULL)) >= 0)
switch(c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -354,7 +352,7 @@ static int parse_argv(int argc, char *argv[]) {
}
if (optind == argc) {
- log_error("Usage: %s [OPTION...] PROGRAM [OPTION...]",
+ log_error("%s: command to execute is missing.",
program_invocation_short_name);
return -EINVAL;
}
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 888f6b7a66..d0bf01468a 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -1255,10 +1255,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- opterr = 0;
-
- while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
-
+ while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
switch (c) {
case 'h':
@@ -1323,17 +1320,11 @@ static int parse_argv(int argc, char *argv[]) {
break;
case '?':
- log_error("Unknown option %s.", argv[optind-1]);
- return -EINVAL;
-
- case ':':
- log_error("Missing argument to %s.", argv[optind-1]);
return -EINVAL;
default:
assert_not_reached("Unhandled option code.");
}
- }
return 1; /* work to do */
}
diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c
index 4d5690c2c0..5c37cffc22 100644
--- a/src/ask-password/ask-password.c
+++ b/src/ask-password/ask-password.c
@@ -50,8 +50,7 @@ static usec_t arg_timeout = DEFAULT_TIMEOUT_USEC;
static bool arg_accept_cached = false;
static bool arg_multiple = false;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] MESSAGE\n\n"
"Query the user for a system passphrase, via the TTY or an UI agent.\n\n"
" -h --help Show this help\n"
@@ -60,10 +59,8 @@ static int help(void) {
" --no-tty Ask question via agent even on TTY\n"
" --accept-cached Accept cached passwords\n"
" --multiple List multiple passwords if available\n"
- " --id=ID Query identifier (e.g. cryptsetup:/dev/sda5)\n",
- program_invocation_short_name);
-
- return 0;
+ " --id=ID Query identifier (e.g. cryptsetup:/dev/sda5)\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -93,12 +90,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_ICON:
arg_icon = optarg;
@@ -133,10 +131,9 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
- if (optind != argc-1) {
- help();
+ if (optind != argc - 1) {
+ log_error("%s: required argument missing.", program_invocation_short_name);
return -EINVAL;
}
@@ -151,7 +148,8 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
- if ((r = parse_argv(argc, argv)) <= 0)
+ r = parse_argv(argc, argv);
+ if (r <= 0)
goto finish;
if (arg_timeout > 0)
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index 9fc5d4e4a4..c1c152239b 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -122,15 +122,12 @@ static int apply_file(const char *path, bool ignore_enoent) {
return r;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
"Registers binary formats.\n\n"
" -h --help Show this help\n"
- " --version Show package version\n",
- program_invocation_short_name);
-
- return 0;
+ " --version Show package version\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -150,12 +147,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -168,7 +166,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 359e273fd9..51b51c4254 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -32,17 +32,14 @@
#include "util.h"
#include "utf8.h"
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] COMMAND ...\n\n"
"Query or change firmware and boot manager settings.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
"Commands:\n"
- " status Show current boot settings\n",
- program_invocation_short_name);
-
- return 0;
+ " status Show current boot settings\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -51,8 +48,8 @@ static int parse_argv(int argc, char *argv[]) {
};
static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, ARG_VERSION },
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, ARG_VERSION },
{}
};
@@ -61,12 +58,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -79,7 +77,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
@@ -268,21 +265,17 @@ static int bootctl_main(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
- int r, retval = EXIT_FAILURE;
+ int r;
log_parse_environment();
log_open();
r = parse_argv(argc, argv);
- if (r < 0)
- goto finish;
- else if (r == 0) {
- retval = EXIT_SUCCESS;
+ if (r <= 0)
goto finish;
- }
r = bootctl_main(argc, argv);
- retval = r < 0 ? EXIT_FAILURE : r;
-finish:
- return retval;
+
+ finish:
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index 5683025b19..c0e176da9b 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -163,7 +163,7 @@ static void help(void) {
DEFAULT_INIT);
}
-static int parse_args(int argc, char *argv[]) {
+static int parse_argv(int argc, char *argv[]) {
static const struct option options[] = {
{"rel", no_argument, NULL, 'r'},
{"freq", required_argument, NULL, 'f'},
@@ -180,12 +180,14 @@ static int parse_args(int argc, char *argv[]) {
{"entropy", no_argument, NULL, 'e'},
{}
};
- int c;
+ int c, r;
- while ((c = getopt_long(argc, argv, "erpf:n:o:i:FCchx:y:", options, NULL)) >= 0) {
- int r;
+ if (getpid() == 1)
+ opterr = 0;
+ while ((c = getopt_long(argc, argv, "erpf:n:o:i:FCchx:y:", options, NULL)) >= 0)
switch (c) {
+
case 'r':
arg_relative = true;
break;
@@ -238,18 +240,22 @@ static int parse_args(int argc, char *argv[]) {
break;
case 'h':
help();
- exit (EXIT_SUCCESS);
+ return 0;
+ case '?':
+ if (getpid() != 1)
+ return -EINVAL;
+ else
+ return 0;
default:
- break;
+ assert_not_reached("Unhandled option code.");
}
- }
- if (arg_hz <= 0.0) {
- fprintf(stderr, "Error: Frequency needs to be > 0\n");
+ if (arg_hz <= 0) {
+ log_error("Frequency needs to be > 0");
return -EINVAL;
}
- return 0;
+ return 1;
}
static void do_journal_append(char *file) {
@@ -314,9 +320,9 @@ int main(int argc, char *argv[]) {
parse_conf();
- r = parse_args(argc, argv);
- if (r < 0)
- return EXIT_FAILURE;
+ r = parse_argv(argc, argv);
+ if (r <= 0)
+ return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
/*
* If the kernel executed us through init=/usr/lib/systemd/systemd-bootchart, then
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 1f17fe8c13..e5713d6af9 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -93,7 +93,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
@@ -156,7 +156,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
/* If the first command line argument is only "x" characters
* we'll write who we are talking to into it, so that "ps" is
diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c
index 052ac8ffca..6e9bd232a9 100644
--- a/src/cgls/cgls.c
+++ b/src/cgls/cgls.c
@@ -46,8 +46,7 @@ static bool arg_all = false;
static int arg_full = -1;
static char* arg_machine = NULL;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [CGROUP...]\n\n"
"Recursively show control group contents.\n\n"
" -h --help Show this help\n"
@@ -56,10 +55,8 @@ static int help(void) {
" -a --all Show all groups, including empty\n"
" -l --full Do not ellipsize output\n"
" -k Include kernel threads in output\n"
- " -M --machine Show container\n",
- program_invocation_short_name);
-
- return 0;
+ " -M --machine Show container\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -84,12 +81,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 1);
assert(argv);
- while ((c = getopt_long(argc, argv, "hkalM:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hkalM:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -122,7 +120,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index fd0023b0a8..509fe4cdc8 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -548,8 +548,7 @@ static int display(Hashmap *a) {
return 0;
}
-static int help(void) {
-
+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,10 +562,8 @@ static int 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: %u)\n",
- program_invocation_short_name, arg_depth);
-
- return 0;
+ " --depth=DEPTH Maximum traversal depth (default: %u)\n"
+ , program_invocation_short_name, arg_depth);
}
static int parse_argv(int argc, char *argv[]) {
@@ -594,12 +591,13 @@ 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) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -674,7 +672,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind < argc) {
log_error("Too many arguments.");
diff --git a/src/core/main.c b/src/core/main.c
index e9909ded5b..d2104cb551 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -952,13 +952,13 @@ static int parse_argv(int argc, char *argv[]) {
* parse_proc_cmdline_word() or ignore. */
case '?':
- default:
- if (getpid() != 1) {
- log_error("Unknown option code %c", c);
+ if (getpid() != 1)
return -EINVAL;
- }
+ else
+ return 0;
- break;
+ default:
+ assert_not_reached("Unhandled option code.");
}
if (optind < argc && getpid() != 1) {
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index fde3ce9c27..1abc140e7d 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -74,9 +74,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 1);
assert(argv);
- opterr = 0;
-
- while ((c = getopt_long(argc, argv, ":", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_LOG_LEVEL:
@@ -115,11 +113,6 @@ static int parse_argv(int argc, char *argv[]) {
break;
case '?':
- log_error("Unknown option %s.", argv[optind-1]);
- return -EINVAL;
-
- case ':':
- log_error("Missing argument to %s.", argv[optind-1]);
return -EINVAL;
default:
diff --git a/src/delta/delta.c b/src/delta/delta.c
index dd7523d473..cd8bd35716 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -473,18 +473,15 @@ static int process_suffix_chop(const char *arg) {
return -EINVAL;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [SUFFIX...]\n\n"
"Find overridden configuration files.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
" --diff[=1|0] Show a diff when overridden files differ\n"
- " -t --type=LIST... Only display a selected set of override types\n",
- program_invocation_short_name);
-
- return 0;
+ " -t --type=LIST... Only display a selected set of override types\n"
+ , program_invocation_short_name);
}
static int parse_flags(const char *flag_str, int flags) {
@@ -534,7 +531,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 1);
assert(argv);
- while ((c = getopt_long(argc, argv, "ht:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "ht:", options, NULL)) >= 0)
switch (c) {
@@ -585,7 +582,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c
index 8cf8dcfabc..ff5bee56f9 100644
--- a/src/detect-virt/detect-virt.c
+++ b/src/detect-virt/detect-virt.c
@@ -36,18 +36,15 @@ static enum {
ONLY_CONTAINER
} arg_mode = ANY_VIRTUALIZATION;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Detect execution in a virtualized environment.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -c --container Only detect whether we are run in a container\n"
" -v --vm Only detect whether we are run in a VM\n"
- " -q --quiet Don't output anything, just set return value\n",
- program_invocation_short_name);
-
- return 0;
+ " -q --quiet Don't output anything, just set return value\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -70,12 +67,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -100,10 +98,10 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind < argc) {
- help();
+ log_error("%s takes no arguments.",
+ program_invocation_short_name);
return -EINVAL;
}
diff --git a/src/escape/escape.c b/src/escape/escape.c
index ba2fb4789f..f2a0721861 100644
--- a/src/escape/escape.c
+++ b/src/escape/escape.c
@@ -37,8 +37,7 @@ static const char *arg_suffix = NULL;
static const char *arg_template = NULL;
static bool arg_path = false;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [NAME...]\n\n"
"Show system and user paths.\n\n"
" -h --help Show this help\n"
@@ -47,10 +46,8 @@ static int help(void) {
" --template=TEMPLATE Insert strings as instance into template\n"
" -u --unescape Unescape strings\n"
" -m --mangle Mangle strings\n"
- " -p --path When escaping/unescaping assume the string is a path\n",
- program_invocation_short_name);
-
- return 0;
+ " -p --path When escaping/unescaping assume the string is a path\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -77,12 +74,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hump", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hump", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -127,7 +125,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc) {
log_error("Not enough arguments.");
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 2c08ad481b..fd73adbac8 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -647,8 +647,7 @@ static int process_root_password(void) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Configures basic settings of the system.\n\n"
" -h --help Show this help\n"
@@ -670,10 +669,8 @@ static int help(void) {
" --copy-timezone Copy timezone from host\n"
" --copy-root-password Copy root password from host\n"
" --copy Copy locale, timezone, root password\n"
- " --setup-machine-id Generate a new random machine ID\n",
- program_invocation_short_name);
-
- return 0;
+ " --setup-machine-id Generate a new random machine ID\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -729,12 +726,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -887,7 +885,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 7e6922b0a0..69da54f1f3 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -321,8 +321,7 @@ static int set_deployment(sd_bus *bus, char **args, unsigned n) {
return set_simple_string(bus, "SetDeployment", args[1]);
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] COMMAND ...\n\n"
"Query or change system hostname.\n\n"
" -h --help Show this help\n"
@@ -338,10 +337,8 @@ static int help(void) {
" set-hostname NAME Set system hostname\n"
" set-icon-name NAME Set icon name for host\n"
" set-chassis NAME Set chassis type for host\n"
- " set-deployment NAME Set deployment environment for host\n",
- program_invocation_short_name);
-
- return 0;
+ " set-deployment NAME Set deployment environment for host\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -371,12 +368,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -415,7 +413,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c
index 6cfe22957a..db81fe3ca3 100644
--- a/src/journal-remote/journal-gatewayd.c
+++ b/src/journal-remote/journal-gatewayd.c
@@ -857,8 +857,7 @@ static int request_handler(
return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found.\n");
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] ...\n\n"
"HTTP server for journal events.\n\n"
" -h --help Show this help\n"
@@ -867,8 +866,6 @@ static int help(void) {
" --key=KEY.PEM Server key in PEM format\n"
" --trust=CERT.PEM Certificat authority certificate in PEM format\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -898,7 +895,8 @@ static int parse_argv(int argc, char *argv[]) {
switch(c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index 1df178691a..c8e3c235ac 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -1370,8 +1370,7 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
default:
- log_error("Unknown option code %c", c);
- return -EINVAL;
+ assert_not_reached("Unknown option code.");
}
if (optind < argc)
diff --git a/src/journal/cat.c b/src/journal/cat.c
index a525bcf3e8..627c0624a5 100644
--- a/src/journal/cat.c
+++ b/src/journal/cat.c
@@ -36,18 +36,15 @@ static char *arg_identifier = NULL;
static int arg_priority = LOG_INFO;
static bool arg_level_prefix = true;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Execute process with stdout/stderr connected to the journal.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -t --identifier=STRING Set syslog identifier\n"
" -p --priority=PRIORITY Set priority value (0..7)\n"
- " --level-prefix=BOOL Control whether level prefix shall be parsed\n",
- program_invocation_short_name);
-
- return 0;
+ " --level-prefix=BOOL Control whether level prefix shall be parsed\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -71,12 +68,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+ht:p:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+ht:p:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -120,7 +118,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 2bc9021022..f5cf85a765 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -81,29 +81,6 @@ static Set *new_matches(void) {
return set;
}
-static int help(void) {
-
- printf("%s [OPTIONS...]\n\n"
- "List or retrieve coredumps from the journal.\n\n"
- "Flags:\n"
- " -h --help Show this help\n"
- " --version Print version string\n"
- " --no-pager Do not pipe output into a pager\n"
- " --no-legend Do not print the column headers.\n"
- " -1 Show information about most recent entry only\n"
- " -F --field=FIELD List all values a certain field takes\n"
- " -o --output=FILE Write output to FILE\n\n"
-
- "Commands:\n"
- " list [MATCHES...] List available coredumps (default)\n"
- " info [MATCHES...] Show detailed information about one or more coredumps\n"
- " dump [MATCHES...] Print first matching coredump to stdout\n"
- " gdb [MATCHES...] Start gdb for the first matching coredump\n"
- , program_invocation_short_name);
-
- return 0;
-}
-
static int add_match(Set *set, const char *match) {
int r = -ENOMEM;
unsigned pid;
@@ -144,6 +121,26 @@ fail:
return r;
}
+static void help(void) {
+ printf("%s [OPTIONS...]\n\n"
+ "List or retrieve coredumps from the journal.\n\n"
+ "Flags:\n"
+ " -h --help Show this help\n"
+ " --version Print version string\n"
+ " --no-pager Do not pipe output into a pager\n"
+ " --no-legend Do not print the column headers.\n"
+ " -1 Show information about most recent entry only\n"
+ " -F --field=FIELD List all values a certain field takes\n"
+ " -o --output=FILE Write output to FILE\n\n"
+
+ "Commands:\n"
+ " list [MATCHES...] List available coredumps (default)\n"
+ " info [MATCHES...] Show detailed information about one or more coredumps\n"
+ " dump [MATCHES...] Print first matching coredump to stdout\n"
+ " gdb [MATCHES...] Start gdb for the first matching coredump\n"
+ , program_invocation_short_name);
+}
+
static int parse_argv(int argc, char *argv[], Set *matches) {
enum {
ARG_VERSION = 0x100,
@@ -171,7 +168,8 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
case 'h':
arg_action = ACTION_NONE;
- return help();
+ help();
+ return 0;
case ARG_VERSION:
arg_action = ACTION_NONE;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 52fd8beb22..5c4a71d618 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -160,7 +160,7 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset
return 0;
}
-static int help(void) {
+static void help(void) {
pager_open_if_enabled();
@@ -218,8 +218,6 @@ static int help(void) {
" --verify Verify journal file consistency\n"
#endif
, program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -306,12 +304,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xrM:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xrM:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -633,7 +632,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_follow && !arg_no_tail && arg_lines < 0)
arg_lines = 10;
diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c
index 4545047011..b6839c13e7 100644
--- a/src/libsystemd/sd-bus/busctl.c
+++ b/src/libsystemd/sd-bus/busctl.c
@@ -320,7 +320,6 @@ static int status(sd_bus *bus, char *argv[]) {
}
static int help(void) {
-
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Introspect the bus.\n\n"
" -h --help Show this help\n"
@@ -341,8 +340,8 @@ static int help(void) {
" list List bus names\n"
" monitor [SERVICE...] Show bus traffic\n"
" status NAME Show name status\n"
- " help Show this help\n",
- program_invocation_short_name);
+ " help Show this help\n"
+ , program_invocation_short_name);
return 0;
}
@@ -386,7 +385,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
switch (c) {
@@ -455,7 +454,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (!arg_unique && !arg_acquired && !arg_activatable)
arg_unique = arg_acquired = arg_activatable = true;
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 8acc212033..69d50076aa 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -440,8 +440,7 @@ static int list_x11_keymaps(sd_bus *bus, char **args, unsigned n) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] COMMAND ...\n\n"
"Query or change system locale and keyboard settings.\n\n"
" -h --help Show this help\n"
@@ -463,10 +462,8 @@ static int help(void) {
" list-x11-keymap-layouts Show known X11 keyboard mapping layouts\n"
" list-x11-keymap-variants [LAYOUT]\n"
" Show known X11 keyboard mapping variants\n"
- " list-x11-keymap-options Show known X11 keyboard mapping options\n",
- program_invocation_short_name);
-
- return 0;
+ " list-x11-keymap-options Show known X11 keyboard mapping options\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -494,12 +491,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -534,7 +532,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index 24e8fb04bd..02b6b25751 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -122,8 +122,7 @@ static int print_inhibitors(sd_bus *bus, sd_bus_error *error) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Execute a process while inhibiting shutdown/sleep/idle.\n\n"
" -h --help Show this help\n"
@@ -135,10 +134,8 @@ static int help(void) {
" --who=STRING A descriptive string who is inhibiting\n"
" --why=STRING A descriptive string why is being inhibited\n"
" --mode=MODE One of block or delay\n"
- " --list List active inhibitors\n",
- program_invocation_short_name);
-
- return 0;
+ " --list List active inhibitors\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -168,12 +165,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -206,7 +204,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_action == ACTION_INHIBIT && argc == 1)
arg_action = ACTION_LIST;
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index ebe9c1f16c..1773276b95 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -1047,8 +1047,7 @@ static int terminate_seat(sd_bus *bus, char **args, unsigned n) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Send control commands to or query the login manager.\n\n"
" -h --help Show this help\n"
@@ -1086,10 +1085,8 @@ static int help(void) {
" show-seat NAME... Show properties of one or more seats\n"
" attach NAME DEVICE... Attach one or more devices to a seat\n"
" flush-devices Flush all device associations\n"
- " terminate-seat NAME... Terminate all sessions on one or more seats\n",
- program_invocation_short_name);
-
- return 0;
+ " terminate-seat NAME... Terminate all sessions on one or more seats\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -1123,12 +1120,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hp:als:H:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hp:als:H:M:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -1195,7 +1193,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c
index 1c933ce600..85bbfc4299 100644
--- a/src/machine-id-setup/machine-id-setup-main.c
+++ b/src/machine-id-setup/machine-id-setup-main.c
@@ -31,16 +31,13 @@
static const char *arg_root = "";
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Initialize /etc/machine-id from a random source.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --root=ROOT Filesystem root\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -62,12 +59,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -84,7 +82,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind < argc) {
log_error("Extraneous arguments");
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 574c988e82..02d5d301c0 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -779,8 +779,7 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Send control commands to or query the virtual machine and container registration manager.\n\n"
" -h --help Show this help\n"
@@ -804,8 +803,6 @@ static int help(void) {
" kill NAME... Send signal to processes of a VM/container\n"
" terminate NAME... Terminate one or more VMs/containers\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -837,12 +834,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hp:als:H:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hp:als:H:M:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -904,7 +902,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index ecb84da6d7..c77b092a62 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -181,15 +181,12 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
return r;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
"Loads statically configured kernel modules.\n\n"
" -h --help Show this help\n"
" --version Show package version\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -209,12 +206,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -227,7 +225,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/network/networkd-wait-online.c b/src/network/networkd-wait-online.c
index d588935e93..6c2fdd1b2c 100644
--- a/src/network/networkd-wait-online.c
+++ b/src/network/networkd-wait-online.c
@@ -30,17 +30,14 @@
static bool arg_quiet = false;
static char **arg_interfaces = NULL;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Block until network is configured.\n\n"
" -h --help Show this help\n"
" --version Print version string\n"
" -q --quiet Do not show status information\n"
- " -i --interface=INTERFACE Block until at least these interfaces have appeared\n",
- program_invocation_short_name);
-
- return 0;
+ " -i --interface=INTERFACE Block until at least these interfaces have appeared\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -62,12 +59,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+hq", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+hq", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case 'q':
arg_quiet = true;
@@ -90,7 +88,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/notify/notify.c b/src/notify/notify.c
index f463c4dd86..2148ae0dfe 100644
--- a/src/notify/notify.c
+++ b/src/notify/notify.c
@@ -42,8 +42,7 @@ static const char *arg_status = NULL;
static bool arg_booted = false;
static const char *arg_readahead = NULL;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [VARIABLE=VALUE...]\n\n"
"Notify the init system about service status updates.\n\n"
" -h --help Show this help\n"
@@ -54,8 +53,6 @@ static int help(void) {
" --booted Returns 0 if the system was booted up with systemd, non-zero otherwise\n"
" --readahead=ACTION Controls read-ahead operations\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -85,12 +82,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -131,7 +129,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc &&
!arg_ready &&
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index b118c739e8..76e86b7e05 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -166,8 +166,7 @@ static unsigned long arg_personality = 0xffffffffLU;
static const char *arg_image = NULL;
static Volatile arg_volatile = VOLATILE_NO;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [PATH] [ARGUMENTS...]\n\n"
"Spawn a minimal namespace container for debugging, testing and building.\n\n"
" -h --help Show this help\n"
@@ -216,8 +215,6 @@ static int help(void) {
" the service unit nspawn is running in\n"
" --volatile[=MODE] Run the system in volatile mode\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -285,12 +282,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+hD:u:bL:M:jS:Z:qi:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+hD:u:bL:M:jS:Z:qi:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -593,7 +591,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_share_system)
arg_register = false;
diff --git a/src/path/path.c b/src/path/path.c
index c2936e0bca..347921a07e 100644
--- a/src/path/path.c
+++ b/src/path/path.c
@@ -77,18 +77,6 @@ static const char* const path_table[_SD_PATH_MAX] = {
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
};
-static int help(void) {
-
- printf("%s [OPTIONS...] [NAME...]\n\n"
- "Show system and user paths.\n\n"
- " -h --help Show this help\n"
- " --version Show package version\n"
- " --suffix=SUFFIX Suffix to append to paths\n",
- program_invocation_short_name);
-
- return 0;
-}
-
static int list_homes(void) {
uint64_t i = 0;
int r = 0;
@@ -135,6 +123,15 @@ static int print_home(const char *n) {
return -ENOTSUP;
}
+static void help(void) {
+ printf("%s [OPTIONS...] [NAME...]\n\n"
+ "Show system and user paths.\n\n"
+ " -h --help Show this help\n"
+ " --version Show package version\n"
+ " --suffix=SUFFIX Suffix to append to paths\n",
+ program_invocation_short_name);
+}
+
static int parse_argv(int argc, char *argv[]) {
enum {
@@ -154,12 +151,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -176,7 +174,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/readahead/readahead.c b/src/readahead/readahead.c
index 73cf538055..35176e9379 100644
--- a/src/readahead/readahead.c
+++ b/src/readahead/readahead.c
@@ -36,31 +36,26 @@ unsigned arg_files_max = 16*1024;
off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX;
usec_t arg_timeout = 2*USEC_PER_MINUTE;
-static int help(void) {
-
- printf("%s [OPTIONS...] collect [DIRECTORY]\n\n"
+static void help(void) {
+ printf("%1$s [OPTIONS...] collect [DIRECTORY]\n\n"
"Collect read-ahead data on early boot.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --files-max=INT Maximum number of files to read ahead\n"
" --file-size-max=BYTES Maximum size of files to read ahead\n"
- " --timeout=USEC Maximum time to spend collecting data\n\n\n",
- program_invocation_short_name);
-
- printf("%s [OPTIONS...] replay [DIRECTORY]\n\n"
+ " --timeout=USEC Maximum time to spend collecting data\n"
+ "\n\n"
+ "%1$s [OPTIONS...] replay [DIRECTORY]\n\n"
"Replay collected read-ahead data on early boot.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
- " --file-size-max=BYTES Maximum size of files to read ahead\n\n\n",
- program_invocation_short_name);
-
- printf("%s [OPTIONS...] analyze [PACK FILE]\n\n"
+ " --file-size-max=BYTES Maximum size of files to read ahead\n"
+ "\n\n"
+ "%1$s [OPTIONS...] analyze [PACK-FILE]\n\n"
"Analyze collected read-ahead data.\n\n"
" -h --help Show this help\n"
" --version Show package version\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -86,12 +81,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -131,11 +127,11 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind != argc-1 &&
optind != argc-2) {
- help();
+ log_error("%s: wrong number of arguments.",
+ program_invocation_short_name);
return -EINVAL;
}
diff --git a/src/resolve-host/resolve-host.c b/src/resolve-host/resolve-host.c
index 80ce9cb237..987b43a0cb 100644
--- a/src/resolve-host/resolve-host.c
+++ b/src/resolve-host/resolve-host.c
@@ -448,7 +448,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h46i:t:c:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h46i:t:c:", options, NULL)) >= 0)
switch(c) {
case 'h':
@@ -514,7 +514,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_type == 0 && arg_class != 0) {
log_error("--class= may only be used in conjunction with --type=");
diff --git a/src/run/run.c b/src/run/run.c
index b9be1455c4..f8f0ea2832 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -48,8 +48,7 @@ static bool arg_nice_set = false;
static char **arg_environment = NULL;
static char **arg_property = NULL;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] COMMAND [ARGS...]\n\n"
"Run the specified command in a transient scope or service unit.\n\n"
" -h --help Show this help\n"
@@ -70,8 +69,6 @@ static int help(void) {
" --nice=NICE Nice level\n"
" --setenv=NAME=VALUE Set environment\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -119,12 +116,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+hrH:M:p:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+hrH:M:p:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -215,7 +213,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc) {
log_error("Command line to execute required.");
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 5adbea5956..ca00eea4ab 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -134,8 +134,7 @@ static int execute(char **modes, char **states) {
return r;
}
-static int help(void) {
-
+static void help(void) {
printf("%s COMMAND\n\n"
"Suspend the system, hibernate the system, or both.\n\n"
"Commands:\n"
@@ -144,10 +143,7 @@ static int help(void) {
" suspend Suspend the system\n"
" hibernate Hibernate the system\n"
" hybrid-sleep Both hibernate and suspend the system\n"
- , program_invocation_short_name
- );
-
- return 0;
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -166,10 +162,11 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+h", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch(c) {
case 'h':
- return help();
+ help();
+ return 0; /* done */
case ARG_VERSION:
puts(PACKAGE_STRING);
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index b791305dc5..f6e6672cdf 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -589,17 +589,13 @@ static int add_listen_socket(Context *context, int fd) {
return 0;
}
-static int help(void) {
-
- printf("%s [HOST:PORT]\n"
- "%s [SOCKET]\n\n"
+static void help(void) {
+ printf("%1$s [HOST:PORT]\n"
+ "%1$s [SOCKET]\n\n"
"Bidirectionally proxy local sockets to another (possibly remote) socket.\n\n"
" -h --help Show this help\n"
" --version Show package version\n",
- program_invocation_short_name,
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -620,12 +616,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -638,7 +635,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc) {
log_error("Not enough parameters.");
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 06defa5b7c..8ce9870432 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -214,16 +214,13 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
return r;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
"Applies kernel sysctl settings.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
- " --prefix=PATH Only apply rules that apply to paths with the specified prefix\n",
- program_invocation_short_name);
-
- return 0;
+ " --prefix=PATH Only apply rules that apply to paths with the specified prefix\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -245,12 +242,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -276,7 +274,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 8ec0db2b2d..daf7e31de9 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5432,7 +5432,7 @@ static int is_system_running(sd_bus *bus, char **args) {
return streq(state, "running") ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static int systemctl_help(void) {
+static void systemctl_help(void) {
pager_open_if_enabled();
@@ -5557,12 +5557,9 @@ static int systemctl_help(void) {
" hibernate Hibernate the system\n"
" hybrid-sleep Hibernate and suspend the system\n",
program_invocation_short_name);
-
- return 0;
}
-static int halt_help(void) {
-
+static void halt_help(void) {
printf("%s [OPTIONS...]%s\n\n"
"%s the system.\n\n"
" --help Show this help\n"
@@ -5578,12 +5575,9 @@ static int halt_help(void) {
arg_action == ACTION_REBOOT ? "Reboot" :
arg_action == ACTION_POWEROFF ? "Power off" :
"Halt");
-
- return 0;
}
-static int shutdown_help(void) {
-
+static void shutdown_help(void) {
printf("%s [OPTIONS...] [TIME] [WALL...]\n\n"
"Shut down the system.\n\n"
" --help Show this help\n"
@@ -5595,12 +5589,9 @@ static int shutdown_help(void) {
" --no-wall Don't send wall message before halt/power-off/reboot\n"
" -c Cancel a pending shutdown\n",
program_invocation_short_name);
-
- return 0;
}
-static int telinit_help(void) {
-
+static void telinit_help(void) {
printf("%s [OPTIONS...] {COMMAND}\n\n"
"Send control commands to the init daemon.\n\n"
" --help Show this help\n"
@@ -5613,18 +5604,13 @@ static int telinit_help(void) {
" q, Q Reload init daemon configuration\n"
" u, U Reexecute init daemon\n",
program_invocation_short_name);
-
- return 0;
}
-static int runlevel_help(void) {
-
+static void runlevel_help(void) {
printf("%s [OPTIONS...]\n\n"
"Prints the previous and current runlevel of the init system.\n\n"
" --help Show this help\n",
program_invocation_short_name);
-
- return 0;
}
static void help_types(void) {
@@ -5719,12 +5705,13 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0)
switch (c) {
case 'h':
- return systemctl_help();
+ systemctl_help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -5992,7 +5979,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_transport != BUS_TRANSPORT_LOCAL && arg_scope != UNIT_FILE_SYSTEM) {
log_error("Cannot access user instance remotely.");
@@ -6032,11 +6018,12 @@ static int halt_parse_argv(int argc, char *argv[]) {
if (runlevel == '0' || runlevel == '6')
arg_force = 2;
- while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return halt_help();
+ halt_help();
+ return 0;
case ARG_HALT:
arg_action = ACTION_HALT;
@@ -6079,7 +6066,6 @@ static int halt_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) {
r = update_reboot_param_file(argc == optind + 1 ? argv[optind] : NULL);
@@ -6164,11 +6150,12 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "HPrhkt:afFc", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "HPrhkt:afFc", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return shutdown_help();
+ shutdown_help();
+ return 0;
case 'H':
arg_action = ACTION_HALT;
@@ -6217,7 +6204,6 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (argc > optind && arg_action != ACTION_CANCEL_SHUTDOWN) {
r = parse_time_spec(argv[optind], &arg_when);
@@ -6278,11 +6264,12 @@ static int telinit_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return telinit_help();
+ telinit_help();
+ return 0;
case ARG_NO_WALL:
arg_no_wall = true;
@@ -6294,10 +6281,10 @@ static int telinit_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc) {
- telinit_help();
+ log_error("%s: required argument missing.",
+ program_invocation_short_name);
return -EINVAL;
}
@@ -6343,11 +6330,12 @@ static int runlevel_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
- return runlevel_help();
+ runlevel_help();
+ return 0;
case '?':
return -EINVAL;
@@ -6355,7 +6343,6 @@ static int runlevel_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind < argc) {
log_error("Too many arguments.");
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index b7c1609242..19568adf7a 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -1413,16 +1413,13 @@ static void free_database(Hashmap *by_name, Hashmap *by_id) {
hashmap_free(by_id);
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
"Creates system user accounts.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
- " --root=PATH Operate on an alternate filesystem root\n",
- program_invocation_short_name);
-
- return 0;
+ " --root=PATH Operate on an alternate filesystem root\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -1444,12 +1441,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -1471,7 +1469,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c
index f5c8bc768d..912b61396a 100644
--- a/src/test/test-libudev.c
+++ b/src/test/test-libudev.c
@@ -1,3 +1,4 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
@@ -423,6 +424,7 @@ int main(int argc, char *argv[]) {
const char *syspath = "/devices/virtual/mem/null";
const char *subsystem = NULL;
char path[1024];
+ int c;
udev = udev_new();
printf("context: %p\n", udev);
@@ -433,34 +435,38 @@ int main(int argc, char *argv[]) {
udev_set_log_fn(udev, log_fn);
printf("set log: %p\n", log_fn);
- for (;;) {
- int option;
- option = getopt_long(argc, argv, "+p:s:dhV", options, NULL);
- if (option == -1)
- break;
+ while ((c = getopt_long(argc, argv, "p:s:dhV", options, NULL)) >= 0)
+ switch (c) {
- switch (option) {
case 'p':
syspath = optarg;
break;
+
case 's':
subsystem = optarg;
break;
+
case 'd':
if (udev_get_log_priority(udev) < LOG_INFO)
udev_set_log_priority(udev, LOG_INFO);
break;
+
case 'h':
printf("--debug --syspath= --subsystem= --help\n");
goto out;
+
case 'V':
printf("%s\n", VERSION);
goto out;
- default:
+
+ case '?':
goto out;
+
+ default:
+ assert_not_reached("Unhandled option code.");
}
- }
+
/* add sys path if needed */
if (!startswith(syspath, "/sys")) {
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 53123154db..36c3f3cfcd 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -374,8 +374,7 @@ static int list_timezones(sd_bus *bus, char **args, unsigned n) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] COMMAND ...\n\n"
"Query or change system time and date settings.\n\n"
" -h --help Show this help message\n"
@@ -393,8 +392,6 @@ static int help(void) {
" set-local-rtc BOOL Control whether RTC is in local time\n"
" set-ntp BOOL Control whether NTP is enabled\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -422,12 +419,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -462,7 +460,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 68cfa55ce9..79fd0b72e7 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1407,8 +1407,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
return 0;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
"Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
" -h --help Show this help\n"
@@ -1421,8 +1420,6 @@ static int help(void) {
" --exclude-prefix=PATH Ignore rules that apply to paths with the specified prefix\n"
" --root=PATH Operate on an alternate filesystem root\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -1456,12 +1453,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -1509,7 +1507,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (!arg_clean && !arg_create && !arg_remove) {
log_error("You need to specify at least one of --clean, --create or --remove.");
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 94ae5670f7..528b899c08 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -588,8 +588,7 @@ finish:
return r;
}
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Process system password requests.\n\n"
" -h --help Show this help\n"
@@ -601,8 +600,6 @@ static int help(void) {
" --plymouth Ask question with Plymouth instead of on TTY\n"
" --console Ask question on /dev/console instead of current TTY\n",
program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -634,12 +631,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -676,10 +674,9 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (optind != argc) {
- help();
+ log_error("%s takes no arguments.", program_invocation_short_name);
return -EINVAL;
}
diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c
index 1c06c1aacd..2c11550467 100644
--- a/src/udev/udevadm.c
+++ b/src/udev/udevadm.c
@@ -1,3 +1,4 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/*
* Copyright (C) 2007-2012 Kay Sievers <kay@vrfy.org>
*
@@ -89,7 +90,7 @@ int main(int argc, char *argv[]) {
};
const char *command;
unsigned int i;
- int rc = 1;
+ int rc = 1, c;
udev = udev_new();
if (udev == NULL)
@@ -100,32 +101,30 @@ int main(int argc, char *argv[]) {
udev_set_log_fn(udev, udev_main_log);
label_init("/dev");
- for (;;) {
- int option;
+ while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0)
+ switch (c) {
- option = getopt_long(argc, argv, "+dhV", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
case 'd':
log_set_max_level(LOG_DEBUG);
udev_set_log_priority(udev, LOG_DEBUG);
break;
+
case 'h':
rc = adm_help(udev, argc, argv);
goto out;
+
case 'V':
rc = adm_version(udev, argc, argv);
goto out;
+
default:
goto out;
}
- }
+
command = argv[optind];
if (command != NULL)
- for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) {
+ for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++)
if (streq(udevadm_cmds[i]->name, command)) {
argc -= optind;
argv += optind;
@@ -134,10 +133,8 @@ int main(int argc, char *argv[]) {
rc = run_command(udev, udevadm_cmds[i], argc, argv);
goto out;
}
- }
- fprintf(stderr, "missing or unknown command\n\n");
- adm_help(udev, argc, argv);
+ fprintf(stderr, "%s: missing or unknown command", program_invocation_short_name);
rc = 2;
out:
label_finish();