From eb9da376d76b48585b3b63b4f91903b54f7abd36 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Nov 2013 18:28:39 +0100 Subject: 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. --- src/tmpfiles/tmpfiles.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/tmpfiles') diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 8051cb36ec..b7f6a2e058 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"); } } -- cgit v1.2.3-54-g00ecf