X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Freadahead%2Freadahead.c;h=35176e93794f33edd67cddc0fc84f79e770e90d6;hb=4c94096027f21d4ed0efe991534a926d39d52369;hp=abeecc763497a704391de6fa56d2ed63118d3d05;hpb=87ce22cc0d097d9cd0297d0141eadba6c573c299;p=elogind.git diff --git a/src/readahead/readahead.c b/src/readahead/readahead.c index abeecc763..35176e937 100644 --- a/src/readahead/readahead.c +++ b/src/readahead/readahead.c @@ -29,50 +29,51 @@ #include "util.h" #include "def.h" +#include "build.h" #include "readahead-common.h" unsigned arg_files_max = 16*1024; off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX; usec_t arg_timeout = 2*USEC_PER_MINUTE; -static int help(void) { - - printf("%s [OPTIONS...] collect [DIRECTORY]\n\n" +static void help(void) { + printf("%1$s [OPTIONS...] collect [DIRECTORY]\n\n" "Collect read-ahead data on early boot.\n\n" " -h --help Show this help\n" - " --max-files=INT Maximum number of files to read ahead\n" + " --version Show package version\n" + " --files-max=INT Maximum number of files to read ahead\n" " --file-size-max=BYTES Maximum size of files to read ahead\n" - " --timeout=USEC Maximum time to spend collecting data\n\n\n", - program_invocation_short_name); - - printf("%s [OPTIONS...] replay [DIRECTORY]\n\n" + " --timeout=USEC Maximum time to spend collecting data\n" + "\n\n" + "%1$s [OPTIONS...] replay [DIRECTORY]\n\n" "Replay collected read-ahead data on early boot.\n\n" " -h --help Show this help\n" - " --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" + " --version Show package version\n" + " --file-size-max=BYTES Maximum size of files to read ahead\n" + "\n\n" + "%1$s [OPTIONS...] analyze [PACK-FILE]\n\n" "Analyze collected read-ahead data.\n\n" - " -h --help Show this help\n", + " -h --help Show this help\n" + " --version Show package version\n", program_invocation_short_name); - - return 0; } static int parse_argv(int argc, char *argv[]) { 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; @@ -80,7 +81,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) switch (c) { @@ -88,6 +89,11 @@ static int parse_argv(int argc, char *argv[]) { help(); return 0; + case ARG_VERSION: + puts(PACKAGE_STRING); + puts(SYSTEMD_FEATURES); + return 0; + case ARG_FILES_MAX: if (safe_atou(optarg, &arg_files_max) < 0 || arg_files_max <= 0) { log_error("Failed to parse maximum number of files %s.", optarg); @@ -108,7 +114,7 @@ static int parse_argv(int argc, char *argv[]) { } case ARG_TIMEOUT: - if (parse_usec(optarg, &arg_timeout) < 0 || arg_timeout <= 0) { + if (parse_sec(optarg, &arg_timeout) < 0 || arg_timeout <= 0) { log_error("Failed to parse timeout %s.", optarg); return -EINVAL; } @@ -119,14 +125,13 @@ 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-1 && optind != argc-2) { - help(); + log_error("%s: wrong number of arguments.", + program_invocation_short_name); return -EINVAL; }