chiark / gitweb /
clients: unify how we invoke getopt_long()
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Nov 2013 17:28:39 +0000 (18:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 6 Nov 2013 17:28:39 +0000 (18:28 +0100)
Among other things this makes sure we always expose a --version command
and show it in the help texts.

34 files changed:
man/systemd-readahead-replay.service.xml
man/systemd-tmpfiles.xml
src/activate/activate.c
src/analyze/analyze.c
src/ask-password/ask-password.c
src/binfmt/binfmt.c
src/boot/bootctl.c
src/cgls/cgls.c
src/cgtop/cgtop.c
src/delta/delta.c
src/detect-virt/detect-virt.c
src/hostname/hostnamectl.c
src/journal/cat.c
src/journal/coredumpctl.c
src/journal/journal-gatewayd.c
src/journal/journalctl.c
src/libsystemd-bus/busctl.c
src/locale/localectl.c
src/login/inhibit.c
src/login/loginctl.c
src/machine-id-setup/machine-id-setup-main.c
src/machine/machinectl.c
src/modules-load/modules-load.c
src/notify/notify.c
src/nspawn/nspawn.c
src/readahead/readahead.c
src/run/run.c
src/sleep/sleep.c
src/socket-proxy/socket-proxyd.c
src/sysctl/sysctl.c
src/systemctl/systemctl.c
src/timedate/timedatectl.c
src/tmpfiles/tmpfiles.c
src/tty-ask-password-agent/tty-ask-password-agent.c

index 806d460..b075f57 100644 (file)
                         </varlistentry>
 
                         <varlistentry>
+                                <term><option>--version</option></term>
+
+                                <listitem><para>Prints a short version
+                                string and exits.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><option>--max-files=</option></term>
 
                                 <listitem><para>Maximum number of
index ba727e1..b90bd75 100644 (file)
                 <para>The following options are understood:</para>
 
                 <variablelist>
+                        <varlistentry>
+                                <term><option>-h</option></term>
+                                <term><option>--help</option></term>
+
+                                <listitem><para>Prints a short help
+                                text and exits.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
+                                <term><option>--version</option></term>
+
+                                <listitem><para>Prints a short version
+                                string and exits.</para></listitem>
+                        </varlistentry>
 
                         <varlistentry>
                                 <term><option>--create</option></term>
                                 prefix. This option can be specified
                                 multiple times.</para></listitem>
                         </varlistentry>
-
-
-                        <varlistentry>
-                                <term><option>--help</option></term>
-
-                                <listitem><para>Prints a short help
-                                text and exits.</para></listitem>
-                        </varlistentry>
-
                 </variablelist>
 
                 <para>It is possible to combine
index 83d25b1..43ab458 100644 (file)
@@ -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) {
index 8f965e7..3b793f6 100644 (file)
@@ -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[]) {
index 238cf12..ea0c623 100644 (file)
@@ -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");
                 }
         }
 
index 5a42b3d..3487602 100644 (file)
@@ -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");
                 }
         }
 
index d25ddef..9387e05 100644 (file)
@@ -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");
                 }
         }
 
index c689b5c..b8e275d 100644 (file)
@@ -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");
                 }
         }
 
index 293a211..e5fc262 100644 (file)
@@ -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");
                 }
         }
 
index b3272d9..4aaf1df 100644 (file)
@@ -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");
                 }
         }
 
index 72ff2a8..2f8b0eb 100644 (file)
@@ -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");
                 }
         }
 
index d8657fa..af42817 100644 (file)
@@ -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");
                 }
         }
 
index ea61578..02b7564 100644 (file)
@@ -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");
                 }
         }
 
index 75c96cc..bcfee46 100644 (file)
@@ -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) {
index d4d4b7e..093dc74 100644 (file)
@@ -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) {
index e38721d..a509104 100644 (file)
@@ -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");
                 }
         }
 
index 92072b2..717b911 100644 (file)
@@ -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");
                 }
         }
 
index c70470f..e8bf510 100644 (file)
@@ -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");
                 }
         }
 
index 404881b..8c0056e 100644 (file)
@@ -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");
                 }
         }
 
index 736db6a..dc96e4b 100644 (file)
@@ -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");
                 }
         }
 
index eb2d514..84af925 100644 (file)
@@ -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");
                 }
         }
 
index ee802b1..894309c 100644 (file)
@@ -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");
                 }
         }
 
index 7772e3d..d37eec3 100644 (file)
@@ -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");
                 }
         }
 
index a688a9f..a145b8f 100644 (file)
@@ -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");
                 }
         }
 
index 9f88713..34a0daf 100644 (file)
@@ -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");
                 }
         }
 
index 29255c9..d6729ec 100644 (file)
@@ -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");
                 }
         }
 
index 567fd97..3fb72e6 100644 (file)
@@ -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");
                 }
         }
 
index a56ab89..b6a6f60 100644 (file)
@@ -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) {
index 05ea88a..8f60ab8 100644 (file)
@@ -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");
                 }
         }
 
index b5670db..67c7872 100644 (file)
@@ -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");
                 }
         }
 
index 9f5e273..9d22aad 100644 (file)
@@ -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");
                 }
         }
 
index 9926a8a..7ce9a82 100644 (file)
@@ -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");
                 }
         }
 
index 8051cb3..b7f6a2e 100644 (file)
@@ -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");
                 }
         }
 
index f463662..c0451c0 100644 (file)
@@ -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");
                 }
         }