From eb9da376d76b48585b3b63b4f91903b54f7abd36 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Nov 2013 18:28:39 +0100 Subject: [PATCH] clients: unify how we invoke getopt_long() Among other things this makes sure we always expose a --version command and show it in the help texts. --- man/systemd-readahead-replay.service.xml | 7 ++++ man/systemd-tmpfiles.xml | 23 ++++++----- src/activate/activate.c | 8 ++-- src/analyze/analyze.c | 23 +++++------ src/ask-password/ask-password.c | 8 ++-- src/binfmt/binfmt.c | 20 +++++++--- src/boot/bootctl.c | 10 ++--- src/cgls/cgls.c | 12 +++--- src/cgtop/cgtop.c | 17 ++++---- src/delta/delta.c | 15 +++---- src/detect-virt/detect-virt.c | 8 ++-- src/hostname/hostnamectl.c | 14 +++---- src/journal/cat.c | 11 +++--- src/journal/coredumpctl.c | 11 +++--- src/journal/journal-gatewayd.c | 13 ++++--- src/journal/journalctl.c | 14 +++---- src/libsystemd-bus/busctl.c | 5 +-- src/locale/localectl.c | 8 ++-- src/login/inhibit.c | 11 +++--- src/login/loginctl.c | 8 ++-- src/machine-id-setup/machine-id-setup-main.c | 8 ++-- src/machine/machinectl.c | 8 ++-- src/modules-load/modules-load.c | 20 +++++++--- src/notify/notify.c | 8 ++-- src/nspawn/nspawn.c | 8 ++-- src/readahead/readahead.c | 21 +++++++--- src/run/run.c | 8 ++-- src/sleep/sleep.c | 8 ++-- src/socket-proxy/socket-proxyd.c | 22 +++++------ src/sysctl/sysctl.c | 15 +++++-- src/systemctl/systemctl.c | 39 +++++++------------ src/timedate/timedatectl.c | 8 ++-- src/tmpfiles/tmpfiles.c | 15 +++++-- .../tty-ask-password-agent.c | 8 ++-- 34 files changed, 227 insertions(+), 215 deletions(-) diff --git a/man/systemd-readahead-replay.service.xml b/man/systemd-readahead-replay.service.xml index 806d46093..b075f572d 100644 --- a/man/systemd-readahead-replay.service.xml +++ b/man/systemd-readahead-replay.service.xml @@ -123,6 +123,13 @@ and exits. + + + + Prints a short version + string and exits. + + diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml index ba727e185..b90bd757e 100644 --- a/man/systemd-tmpfiles.xml +++ b/man/systemd-tmpfiles.xml @@ -91,6 +91,20 @@ The following options are understood: + + + + + Prints a short help + text and exits. + + + + + + Prints a short version + string and exits. + @@ -131,15 +145,6 @@ prefix. This option can be specified multiple times. - - - - - - Prints a short help - text and exits. - - It is possible to combine diff --git a/src/activate/activate.c b/src/activate/activate.c index 83d25b13a..43ab45881 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -336,7 +336,7 @@ static int parse_argv(int argc, char *argv[]) { { "listen", required_argument, NULL, 'l' }, { "accept", no_argument, NULL, 'a' }, { "environment", required_argument, NULL, 'E' }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -347,8 +347,7 @@ static int parse_argv(int argc, char *argv[]) { while ((c = getopt_long(argc, argv, "+hl:saE:", options, NULL)) >= 0) switch(c) { case 'h': - help(); - return 0 /* done */; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -379,8 +378,7 @@ 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) { diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 8f965e7a8..3b793f666 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1151,7 +1151,7 @@ static int set_log_level(sd_bus *bus, char **args) { return 0; } -static void help(void) { +static int help(void) { pager_open_if_enabled(); @@ -1186,11 +1186,11 @@ static void help(void) { /* When updating this list, including descriptions, apply * changes to shell-completion/bash/systemd and * shell-completion/systemd-zsh-completion.zsh too. */ + + return 0; } static int parse_argv(int argc, char *argv[]) { - int r; - enum { ARG_VERSION = 0x100, ARG_ORDER, @@ -1214,18 +1214,20 @@ static int parse_argv(int argc, char *argv[]) { { "to-pattern", required_argument, NULL, ARG_DOT_TO_PATTERN }, { "fuzz", required_argument, NULL, ARG_FUZZ }, { "no-pager", no_argument, NULL, ARG_NO_PAGER }, - { NULL, 0, NULL, 0 } + {} }; + int r, c; + assert(argc >= 0); assert(argv); - for (;;) { - switch (getopt_long(argc, argv, "hH:M:", options, NULL)) { + while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) { + + switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -1280,9 +1282,6 @@ static int parse_argv(int argc, char *argv[]) { arg_host = optarg; break; - case -1: - return 1; - case '?': return -EINVAL; @@ -1290,6 +1289,8 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached("Unhandled option"); } } + + return 1; } int main(int argc, char *argv[]) { diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c index 238cf1208..ea0c62397 100644 --- a/src/ask-password/ask-password.c +++ b/src/ask-password/ask-password.c @@ -81,7 +81,7 @@ static int parse_argv(int argc, char *argv[]) { { "no-tty", no_argument, NULL, ARG_NO_TTY }, { "accept-cached", no_argument, NULL, ARG_ACCEPT_CACHED }, { "multiple", no_argument, NULL, ARG_MULTIPLE }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -94,8 +94,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_ICON: arg_icon = optarg; @@ -124,8 +123,7 @@ 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"); } } diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 5a42b3dbe..3487602e4 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -34,6 +34,7 @@ #include "util.h" #include "conf-files.h" #include "fileio.h" +#include "build.h" static const char conf_file_dirs[] = "/etc/binfmt.d\0" @@ -125,7 +126,8 @@ static int help(void) { printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n" "Registers binary formats.\n\n" - " -h --help Show this help\n", + " -h --help Show this help\n" + " --version Show package version\n", program_invocation_short_name); return 0; @@ -133,9 +135,14 @@ static int help(void) { static int parse_argv(int argc, char *argv[]) { + enum { + ARG_VERSION = 0x100, + }; + static const struct option options[] = { { "help", no_argument, NULL, 'h' }, - { NULL, 0, NULL, 0 } + { "version", no_argument, NULL, ARG_VERSION }, + {} }; int c; @@ -148,15 +155,18 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); + return help(); + + case ARG_VERSION: + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case '?': return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index d25ddef6e..9387e05d0 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -33,6 +33,7 @@ #include "utf8.h" static int help(void) { + printf("%s [OPTIONS...] COMMAND ...\n\n" "Query or change firmware and boot manager settings.\n\n" " -h --help Show this help\n" @@ -52,20 +53,20 @@ static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, - { NULL, 0, NULL, 0 } + {} }; int c; assert(argc >= 0); assert(argv); + while ((c = getopt_long(argc, argv, "+hH:P", options, NULL)) >= 0) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -76,8 +77,7 @@ 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"); } } diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index c689b5c47..b8e275d01 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -42,7 +42,7 @@ static bool arg_all = false; static int arg_full = -1; static char* arg_machine = NULL; -static void help(void) { +static int help(void) { printf("%s [OPTIONS...] [CGROUP...]\n\n" "Recursively show control group contents.\n\n" @@ -54,6 +54,8 @@ static void help(void) { " -k Include kernel threads in output\n" " -M --machine Show container\n", program_invocation_short_name); + + return 0; } static int parse_argv(int argc, char *argv[]) { @@ -70,7 +72,7 @@ static int parse_argv(int argc, char *argv[]) { { "all", no_argument, NULL, 'a' }, { "full", no_argument, NULL, 'l' }, { "machine", required_argument, NULL, 'M' }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -83,8 +85,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -115,8 +116,7 @@ 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"); } } diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 293a2113b..e5fc26235 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -548,7 +548,7 @@ static int display(Hashmap *a) { return 0; } -static void help(void) { +static int help(void) { printf("%s [OPTIONS...]\n\n" "Show top control groups by their resource usage.\n\n" @@ -565,10 +565,8 @@ static void help(void) { " -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"); + return 0; } static int parse_argv(int argc, char *argv[]) { @@ -587,7 +585,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; @@ -601,11 +599,11 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: - version(); + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case ARG_CPU_TYPE: @@ -674,8 +672,7 @@ 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"); } } diff --git a/src/delta/delta.c b/src/delta/delta.c index b3272d916..4aaf1dfb1 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -431,7 +431,7 @@ static int process_suffix_chop(const char *prefixes, const char *suffix, const c return -EINVAL; } -static void help(void) { +static int help(void) { printf("%s [OPTIONS...] [SUFFIX...]\n\n" "Find overridden configuration files.\n\n" @@ -441,6 +441,8 @@ static void help(void) { " --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; } static int parse_flags(const char *flag_str, int flags) { @@ -482,7 +484,7 @@ static int parse_argv(int argc, char *argv[]) { { "no-pager", no_argument, NULL, ARG_NO_PAGER }, { "diff", optional_argument, NULL, ARG_DIFF }, { "type", required_argument, NULL, 't' }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -507,9 +509,6 @@ static int parse_argv(int argc, char *argv[]) { arg_no_pager = true; break; - case '?': - return -EINVAL; - case 't': { int f; f = parse_flags(optarg, arg_flags); @@ -538,9 +537,11 @@ static int parse_argv(int argc, char *argv[]) { } break; - default: - log_error("Unknown option code %c", c); + case '?': return -EINVAL; + + default: + assert_not_reached("Unhandled option"); } } diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c index 72ff2a858..2f8b0ebbb 100644 --- a/src/detect-virt/detect-virt.c +++ b/src/detect-virt/detect-virt.c @@ -62,7 +62,7 @@ static int parse_argv(int argc, char *argv[]) { { "container", no_argument, NULL, 'c' }, { "vm", optional_argument, NULL, 'v' }, { "quiet", no_argument, NULL, 'q' }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -75,8 +75,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -99,8 +98,7 @@ 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"); } } diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index d8657fa4d..af4281791 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -314,13 +314,13 @@ static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, - { "transient", no_argument, NULL, ARG_TRANSIENT }, - { "static", no_argument, NULL, ARG_STATIC }, - { "pretty", no_argument, NULL, ARG_PRETTY }, + { "transient", no_argument, NULL, ARG_TRANSIENT }, + { "static", no_argument, NULL, ARG_STATIC }, + { "pretty", no_argument, NULL, ARG_PRETTY }, { "host", required_argument, NULL, 'H' }, { "machine", required_argument, NULL, 'M' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -333,8 +333,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -371,8 +370,7 @@ 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"); } } diff --git a/src/journal/cat.c b/src/journal/cat.c index ea6157835..02b75642a 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -63,7 +63,7 @@ static int parse_argv(int argc, char *argv[]) { { "identifier", required_argument, NULL, 't' }, { "priority", required_argument, NULL, 'p' }, { "level-prefix", required_argument, NULL, ARG_LEVEL_PREFIX }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -76,8 +76,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -115,9 +114,11 @@ static int parse_argv(int argc, char *argv[]) { break; } - default: - log_error("Unknown option code %c", c); + case '?': return -EINVAL; + + default: + assert_not_reached("Unhandled option"); } } diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 75c96cc08..bcfee46da 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -155,7 +155,7 @@ static int parse_argv(int argc, char *argv[], Set *matches) { { "no-legend", no_argument, NULL, ARG_NO_LEGEND }, { "output", required_argument, NULL, 'o' }, { "field", required_argument, NULL, 'F' }, - { NULL, 0, NULL, 0 } + {} }; assert(argc >= 0); @@ -163,15 +163,15 @@ static int parse_argv(int argc, char *argv[], Set *matches) { while ((c = getopt_long(argc, argv, "ho:F:", options, NULL)) >= 0) switch(c) { + case 'h': - help(); arg_action = ACTION_NONE; - return 0; + return help(); case ARG_VERSION: + arg_action = ACTION_NONE; puts(PACKAGE_STRING); puts(SYSTEMD_FEATURES); - arg_action = ACTION_NONE; return 0; case ARG_NO_PAGER: @@ -209,8 +209,7 @@ static int parse_argv(int argc, char *argv[], Set *matches) { return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } if (optind < argc) { diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c index d4d4b7ef0..093dc74e2 100644 --- a/src/journal/journal-gatewayd.c +++ b/src/journal/journal-gatewayd.c @@ -935,22 +935,24 @@ static int parse_argv(int argc, char *argv[]) { { "version", no_argument, NULL, ARG_VERSION }, { "key", required_argument, NULL, ARG_KEY }, { "cert", required_argument, NULL, ARG_CERT }, - { NULL, 0, NULL, 0 } + {} }; assert(argc >= 0); assert(argv); while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) + switch(c) { + + case 'h': + return help(); + case ARG_VERSION: puts(PACKAGE_STRING); puts(SYSTEMD_FEATURES); return 0; - case 'h': - return help(); - case ARG_KEY: if (key_pem) { log_error("Key file specified twice"); @@ -981,8 +983,7 @@ 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) { diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index e38721df4..a5091042d 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -248,7 +248,7 @@ static int parse_argv(int argc, char *argv[]) { { "dump-catalog", no_argument, NULL, ARG_DUMP_CATALOG }, { "update-catalog", no_argument, NULL, ARG_UPDATE_CATALOG }, { "reverse", no_argument, NULL, 'r' }, - { NULL, 0, NULL, 0 } + {} }; int c, r; @@ -261,8 +261,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -543,9 +542,6 @@ static int parse_argv(int argc, char *argv[]) { return log_oom(); break; - case '?': - return -EINVAL; - case 'F': arg_field = optarg; break; @@ -570,9 +566,11 @@ static int parse_argv(int argc, char *argv[]) { arg_reverse = true; break; - default: - log_error("Unknown option code %c", c); + case '?': return -EINVAL; + + default: + assert_not_reached("Unhandled option"); } } diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c index 92072b247..717b91120 100644 --- a/src/libsystemd-bus/busctl.c +++ b/src/libsystemd-bus/busctl.c @@ -220,7 +220,7 @@ static int parse_argv(int argc, char *argv[]) { { "address", required_argument, NULL, ARG_ADDRESS }, { "no-unique", no_argument, NULL, ARG_NO_UNIQUE }, { "match", required_argument, NULL, ARG_MATCH }, - { NULL, 0, NULL, 0 }, + {}, }; int c; @@ -279,8 +279,7 @@ 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"); } } diff --git a/src/locale/localectl.c b/src/locale/localectl.c index c70470fe0..e8bf51057 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -654,7 +654,7 @@ static int parse_argv(int argc, char *argv[]) { { "machine", required_argument, NULL, 'M' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, { "no-convert", no_argument, NULL, ARG_NO_CONVERT }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -667,8 +667,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -701,8 +700,7 @@ 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"); } } diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 404881be6..8c0056e50 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -160,7 +160,7 @@ static int parse_argv(int argc, char *argv[]) { { "why", required_argument, NULL, ARG_WHY }, { "mode", required_argument, NULL, ARG_MODE }, { "list", no_argument, NULL, ARG_LIST }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -173,8 +173,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -201,9 +200,11 @@ static int parse_argv(int argc, char *argv[]) { arg_action = ACTION_LIST; break; - default: - log_error("Unknown option code %c", c); + case '?': return -EINVAL; + + default: + assert_not_reached("Unhandled option"); } } diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 736db6a11..dc96e4bd6 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1396,7 +1396,7 @@ static int parse_argv(int argc, char *argv[]) { { "host", required_argument, NULL, 'H' }, { "privileged", no_argument, NULL, 'P' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -1409,8 +1409,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -1475,8 +1474,7 @@ 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"); } } diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index eb2d51485..84af925f5 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -49,7 +49,7 @@ static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -62,8 +62,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -74,8 +73,7 @@ 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"); } } diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index ee802b1e8..894309c7d 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -686,7 +686,7 @@ static int parse_argv(int argc, char *argv[]) { { "host", required_argument, NULL, 'H' }, { "machine", required_argument, NULL, 'M' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, - { NULL, 0, NULL, 0 } + {} }; int c, r; @@ -699,8 +699,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -760,8 +759,7 @@ 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"); } } diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 7772e3dc2..d37eec3f9 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -34,6 +34,7 @@ #include "strv.h" #include "conf-files.h" #include "fileio.h" +#include "build.h" static char **arg_proc_cmdline_modules = NULL; @@ -217,7 +218,8 @@ static int help(void) { printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n" "Loads statically configured kernel modules.\n\n" - " -h --help Show this help\n", + " -h --help Show this help\n" + " --version Show package version\n", program_invocation_short_name); return 0; @@ -225,9 +227,14 @@ static int help(void) { static int parse_argv(int argc, char *argv[]) { + enum { + ARG_VERSION = 0x100, + }; + static const struct option options[] = { { "help", no_argument, NULL, 'h' }, - { NULL, 0, NULL, 0 } + { "version", no_argument, NULL, ARG_VERSION }, + {} }; int c; @@ -240,15 +247,18 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); + return help(); + + case ARG_VERSION: + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case '?': return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } diff --git a/src/notify/notify.c b/src/notify/notify.c index a688a9f87..a145b8fd1 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -77,7 +77,7 @@ static int parse_argv(int argc, char *argv[]) { { "status", required_argument, NULL, ARG_STATUS }, { "booted", no_argument, NULL, ARG_BOOTED }, { "readahead", required_argument, NULL, ARG_READAHEAD }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -90,8 +90,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -130,8 +129,7 @@ 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"); } } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 9f887134c..34a0dafa6 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -165,7 +165,7 @@ static int parse_argv(int argc, char *argv[]) { { "bind-ro", required_argument, NULL, ARG_BIND_RO }, { "machine", required_argument, NULL, 'M' }, { "slice", required_argument, NULL, 'S' }, - { NULL, 0, NULL, 0 } + {} }; int c, r; @@ -178,8 +178,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -329,8 +328,7 @@ 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"); } } diff --git a/src/readahead/readahead.c b/src/readahead/readahead.c index 29255c9f0..d6729ec94 100644 --- a/src/readahead/readahead.c +++ b/src/readahead/readahead.c @@ -29,6 +29,7 @@ #include "util.h" #include "def.h" +#include "build.h" #include "readahead-common.h" unsigned arg_files_max = 16*1024; @@ -40,6 +41,7 @@ static int help(void) { printf("%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" " --max-files=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", @@ -48,12 +50,14 @@ static int help(void) { printf("%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" "Analyze collected read-ahead data.\n\n" - " -h --help Show this help\n", + " -h --help Show this help\n" + " --version Show package version\n", program_invocation_short_name); return 0; @@ -62,17 +66,19 @@ static int help(void) { static int parse_argv(int argc, char *argv[]) { enum { - ARG_FILES_MAX = 0x100, + ARG_VERSION = 0x100, + ARG_FILES_MAX, ARG_FILE_SIZE_MAX, ARG_TIMEOUT }; static const struct option options[] = { { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, { "files-max", required_argument, NULL, ARG_FILES_MAX }, { "file-size-max", required_argument, NULL, ARG_FILE_SIZE_MAX }, { "timeout", required_argument, NULL, ARG_TIMEOUT }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -85,7 +91,11 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); + return help(); + + case ARG_VERSION: + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case ARG_FILES_MAX: @@ -119,8 +129,7 @@ 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"); } } diff --git a/src/run/run.c b/src/run/run.c index 567fd97e3..3fb72e610 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -85,7 +85,7 @@ static int parse_argv(int argc, char *argv[]) { { "send-sighup", no_argument, NULL, ARG_SEND_SIGHUP }, { "host", required_argument, NULL, 'H' }, { "machine", required_argument, NULL, 'M' }, - { NULL, 0, NULL, 0 }, + {}, }; int c; @@ -98,8 +98,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -152,8 +151,7 @@ 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"); } } diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index a56ab89e5..b6a6f60d0 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -154,7 +154,7 @@ static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -165,8 +165,7 @@ static int parse_argv(int argc, char *argv[]) { while ((c = getopt_long(argc, argv, "+h", options, NULL)) >= 0) switch(c) { case 'h': - help(); - return 0 /* done */; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -177,8 +176,7 @@ 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 (argc - optind != 1) { diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index 05ea88ac6..8f60ab88f 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -37,6 +37,7 @@ #include "socket-util.h" #include "util.h" #include "event-util.h" +#include "build.h" #define BUFFER_SIZE 16384 #define _cleanup_freeaddrinfo_ _cleanup_(freeaddrinfop) @@ -511,10 +512,6 @@ static int help(void) { return 0; } -static void version(void) { - puts(PACKAGE_STRING " socket-proxyd"); -} - static int parse_argv(int argc, char *argv[], struct proxy *p) { enum { @@ -526,7 +523,7 @@ static int parse_argv(int argc, char *argv[], struct proxy *p) { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, { "ignore-env", no_argument, NULL, ARG_IGNORE_ENV}, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -539,23 +536,22 @@ static int parse_argv(int argc, char *argv[], struct proxy *p) { switch (c) { case 'h': - help(); - return 0; - - case '?': - return -EINVAL; + return help(); case ARG_VERSION: - version(); + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case ARG_IGNORE_ENV: p->ignore_env = true; continue; - default: - log_error("Unknown option code %c", c); + case '?': return -EINVAL; + + default: + assert_not_reached("Unhandled option"); } } diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index b5670dbb8..67c787225 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -35,6 +35,7 @@ #include "path-util.h" #include "conf-files.h" #include "fileio.h" +#include "build.h" static char **arg_prefixes = NULL; @@ -205,6 +206,7 @@ static int 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); @@ -214,13 +216,15 @@ static int help(void) { static int parse_argv(int argc, char *argv[]) { enum { + ARG_VERSION = 0x100, ARG_PREFIX }; static const struct option options[] = { { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, { "prefix", required_argument, NULL, ARG_PREFIX }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -233,7 +237,11 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); + return help(); + + case ARG_VERSION: + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case ARG_PREFIX: { @@ -258,8 +266,7 @@ 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"); } } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 9f5e2735a..9d22aad28 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4961,7 +4961,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "output", required_argument, NULL, 'o' }, { "plain", no_argument, NULL, ARG_PLAIN }, { "state", required_argument, NULL, ARG_STATE }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -4974,8 +4974,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - systemctl_help(); - return 0; + return systemctl_help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -5221,8 +5220,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code '%c'.", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } @@ -5252,7 +5250,7 @@ static int halt_parse_argv(int argc, char *argv[]) { { "wtmp-only", no_argument, NULL, 'w' }, { "no-wtmp", no_argument, NULL, 'd' }, { "no-wall", no_argument, NULL, ARG_NO_WALL }, - { NULL, 0, NULL, 0 } + {} }; int c, runlevel; @@ -5268,8 +5266,7 @@ static int halt_parse_argv(int argc, char *argv[]) { switch (c) { case ARG_HELP: - halt_help(); - return 0; + return halt_help(); case ARG_HALT: arg_action = ACTION_HALT; @@ -5310,8 +5307,7 @@ static int halt_parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code '%c'.", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } @@ -5386,7 +5382,7 @@ static int shutdown_parse_argv(int argc, char *argv[]) { { "reboot", no_argument, NULL, 'r' }, { "kexec", no_argument, NULL, 'K' }, /* not documented extension */ { "no-wall", no_argument, NULL, ARG_NO_WALL }, - { NULL, 0, NULL, 0 } + {} }; int c, r; @@ -5398,8 +5394,7 @@ static int shutdown_parse_argv(int argc, char *argv[]) { switch (c) { case ARG_HELP: - shutdown_help(); - return 0; + return shutdown_help(); case 'H': arg_action = ACTION_HALT; @@ -5446,8 +5441,7 @@ static int shutdown_parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code '%c'.", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } @@ -5482,7 +5476,7 @@ static int telinit_parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, ARG_HELP }, { "no-wall", no_argument, NULL, ARG_NO_WALL }, - { NULL, 0, NULL, 0 } + {} }; static const struct { @@ -5514,8 +5508,7 @@ static int telinit_parse_argv(int argc, char *argv[]) { switch (c) { case ARG_HELP: - telinit_help(); - return 0; + return telinit_help(); case ARG_NO_WALL: arg_no_wall = true; @@ -5525,8 +5518,7 @@ static int telinit_parse_argv(int argc, char *argv[]) { return -EINVAL; default: - log_error("Unknown option code '%c'.", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } @@ -5569,7 +5561,7 @@ static int runlevel_parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, ARG_HELP }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -5581,15 +5573,14 @@ static int runlevel_parse_argv(int argc, char *argv[]) { switch (c) { case ARG_HELP: - runlevel_help(); + return runlevel_help(); return 0; case '?': return -EINVAL; default: - log_error("Unknown option code '%c'.", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index 9926a8a88..7ce9a824e 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -445,7 +445,7 @@ static int parse_argv(int argc, char *argv[]) { { "machine", required_argument, NULL, 'M' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, { "adjust-system-clock", no_argument, NULL, ARG_ADJUST_SYSTEM_CLOCK }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -458,8 +458,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -492,8 +491,7 @@ 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"); } } diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 8051cb36e..b7f6a2e05 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -52,6 +52,7 @@ #include "conf-files.h" #include "capability.h" #include "specifier.h" +#include "build.h" /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates * them in the file system. This is intended to be used to create @@ -1266,6 +1267,7 @@ static int 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" + " --version Show package version\n" " --create Create marked files/directories\n" " --clean Clean up marked directories\n" " --remove Remove marked files/directories\n" @@ -1279,6 +1281,7 @@ static int help(void) { static int parse_argv(int argc, char *argv[]) { enum { + ARG_VERSION = 0x100, ARG_CREATE, ARG_CLEAN, ARG_REMOVE, @@ -1288,12 +1291,13 @@ static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, { "create", no_argument, NULL, ARG_CREATE }, { "clean", no_argument, NULL, ARG_CLEAN }, { "remove", no_argument, NULL, ARG_REMOVE }, { "prefix", required_argument, NULL, ARG_PREFIX }, { "exclude-prefix", required_argument, NULL, ARG_EXCLUDE_PREFIX }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -1306,7 +1310,11 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); + return help(); + + case ARG_VERSION: + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); return 0; case ARG_CREATE: @@ -1335,8 +1343,7 @@ 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"); } } 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 f463662d6..c0451c0fd 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -666,7 +666,7 @@ static int parse_argv(int argc, char *argv[]) { { "wall", no_argument, NULL, ARG_WALL }, { "plymouth", no_argument, NULL, ARG_PLYMOUTH }, { "console", no_argument, NULL, ARG_CONSOLE }, - { NULL, 0, NULL, 0 } + {} }; int c; @@ -679,8 +679,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); @@ -715,8 +714,7 @@ 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"); } } -- 2.30.2