From 33f2af1c09318c38a3fe8543cb1df70fd910d628 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 10 Oct 2019 10:51:04 +0200 Subject: [PATCH] Change --version option handling and support -V short option. Fixes #480. --- src/cryptsetup.c | 14 ++++++-------- src/cryptsetup_reencrypt.c | 14 ++++++-------- src/integritysetup.c | 15 ++++++--------- src/veritysetup.c | 15 ++++++--------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/cryptsetup.c b/src/cryptsetup.c index bc93d57c..0064dae5 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -54,7 +54,6 @@ static uint64_t opt_offset = 0; static uint64_t opt_skip = 0; static int opt_skip_valid = 0; static int opt_readonly = 0; -static int opt_version_mode = 0; static int opt_timeout = 0; static int opt_tries = 3; static int opt_align_payload = 0; @@ -3293,6 +3292,11 @@ static void help(poptContext popt_context, #if defined(ENABLE_LUKS_ADJUST_XTS_KEYSIZE) && DEFAULT_LUKS1_KEYBITS != 512 log_std(_("\tLUKS: Default keysize with XTS mode (two internal keys) will be doubled.\n")); #endif + poptFreeContext(popt_context); + exit(EXIT_SUCCESS); + } else if (key->shortName == 'V') { + log_std("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION); + poptFreeContext(popt_context); exit(EXIT_SUCCESS); } else usage(popt_context, EXIT_SUCCESS, NULL, NULL); @@ -3342,11 +3346,11 @@ int main(int argc, const char **argv) { NULL, '\0', POPT_ARG_CALLBACK, help, 0, NULL, NULL }, { "help", '?', POPT_ARG_NONE, NULL, 0, N_("Show this help message"), NULL }, { "usage", '\0', POPT_ARG_NONE, NULL, 0, N_("Display brief usage"), NULL }, + { "version",'V', POPT_ARG_NONE, NULL, 0, N_("Print package version"), NULL }, POPT_TABLEEND }; static struct poptOption popt_options[] = { { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_help_options, 0, N_("Help options:"), NULL }, - { "version", '\0', POPT_ARG_NONE, &opt_version_mode, 0, N_("Print package version"), NULL }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL }, { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL }, { "debug-json", '\0', POPT_ARG_NONE, &opt_debug_json, 0, N_("Show debug messages including JSON metadata"), NULL }, @@ -3491,12 +3495,6 @@ int main(int argc, const char **argv) usage(popt_context, EXIT_FAILURE, poptStrerror(r), poptBadOption(popt_context, POPT_BADOPTION_NOALIAS)); - if (opt_version_mode) { - log_std("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION); - poptFreeContext(popt_context); - exit(EXIT_SUCCESS); - } - if (!(aname = poptGetArg(popt_context))) usage(popt_context, EXIT_FAILURE, _("Argument missing."), poptGetInvocationName(popt_context)); diff --git a/src/cryptsetup_reencrypt.c b/src/cryptsetup_reencrypt.c index 48c040c8..693c55bd 100644 --- a/src/cryptsetup_reencrypt.c +++ b/src/cryptsetup_reencrypt.c @@ -42,7 +42,6 @@ static const char *opt_pbkdf = NULL; static long opt_pbkdf_memory = DEFAULT_LUKS2_MEMORY_KB; static long opt_pbkdf_parallel = DEFAULT_LUKS2_PARALLEL_THREADS; static long opt_pbkdf_iterations = 0; -static int opt_version_mode = 0; static int opt_random = 0; static int opt_urandom = 0; static int opt_bsize = 4; @@ -1576,6 +1575,11 @@ static void help(poptContext popt_context, if (key->shortName == '?') { log_std("%s %s\n", PACKAGE_REENC, PACKAGE_VERSION); poptPrintHelp(popt_context, stdout, 0); + poptFreeContext(popt_context); + exit(EXIT_SUCCESS); + } else if (key->shortName == 'V') { + log_std("%s %s\n", PACKAGE_REENC, PACKAGE_VERSION); + poptFreeContext(popt_context); exit(EXIT_SUCCESS); } else usage(popt_context, EXIT_SUCCESS, NULL, NULL); @@ -1587,11 +1591,11 @@ int main(int argc, const char **argv) { NULL, '\0', POPT_ARG_CALLBACK, help, 0, NULL, NULL }, { "help", '?', POPT_ARG_NONE, NULL, 0, N_("Show this help message"), NULL }, { "usage", '\0', POPT_ARG_NONE, NULL, 0, N_("Display brief usage"), NULL }, + { "version",'V', POPT_ARG_NONE, NULL, 0, N_("Print package version"), NULL }, POPT_TABLEEND }; static struct poptOption popt_options[] = { { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_help_options, 0, N_("Help options:"), NULL }, - { "version", '\0', POPT_ARG_NONE, &opt_version_mode, 0, N_("Print package version"), NULL }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL }, { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL }, { "block-size", 'B', POPT_ARG_INT, &opt_bsize, 0, N_("Reencryption block size"), N_("MiB") }, @@ -1644,12 +1648,6 @@ int main(int argc, const char **argv) usage(popt_context, EXIT_FAILURE, poptStrerror(r), poptBadOption(popt_context, POPT_BADOPTION_NOALIAS)); - if (opt_version_mode) { - log_std("%s %s\n", PACKAGE_REENC, PACKAGE_VERSION); - poptFreeContext(popt_context); - exit(EXIT_SUCCESS); - } - if (!opt_batch_mode) log_verbose(_("Reencryption will change: %s%s%s%s%s%s."), opt_keep_key ? "" : _("volume key"), diff --git a/src/integritysetup.c b/src/integritysetup.c index b0c56a81..2a9dccca 100644 --- a/src/integritysetup.c +++ b/src/integritysetup.c @@ -61,8 +61,6 @@ static int opt_integrity_bitmap = 0; static int opt_integrity_recalculate = 0; -static int opt_version_mode = 0; - static const char **action_argv; static int action_argc; @@ -499,6 +497,11 @@ static void help(poptContext popt_context, log_std(_("\nDefault compiled-in dm-integrity parameters:\n" "\tTag size: %u bytes, Checksum algorithm: %s\n"), DEFAULT_TAG_SIZE, DEFAULT_ALG_NAME); + poptFreeContext(popt_context); + exit(EXIT_SUCCESS); + } else if (key->shortName == 'V') { + log_std("%s %s\n", PACKAGE_INTEGRITY, PACKAGE_VERSION); + poptFreeContext(popt_context); exit(EXIT_SUCCESS); } else usage(popt_context, EXIT_SUCCESS, NULL, NULL); @@ -523,11 +526,11 @@ int main(int argc, const char **argv) { NULL, '\0', POPT_ARG_CALLBACK, help, 0, NULL, NULL }, { "help", '?', POPT_ARG_NONE, NULL, 0, N_("Show this help message"), NULL }, { "usage", '\0', POPT_ARG_NONE, NULL, 0, N_("Display brief usage"), NULL }, + { "version",'V', POPT_ARG_NONE, NULL, 0, N_("Print package version"), NULL }, POPT_TABLEEND }; static struct poptOption popt_options[] = { { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_help_options, 0, N_("Help options:"), NULL }, - { "version", '\0', POPT_ARG_NONE, &opt_version_mode, 0, N_("Print package version"), NULL }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL }, { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL }, { "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL }, @@ -587,12 +590,6 @@ int main(int argc, const char **argv) usage(popt_context, EXIT_FAILURE, poptStrerror(r), poptBadOption(popt_context, POPT_BADOPTION_NOALIAS)); - if (opt_version_mode) { - log_std("%s %s\n", PACKAGE_INTEGRITY, PACKAGE_VERSION); - poptFreeContext(popt_context); - exit(EXIT_SUCCESS); - } - if (!(aname = poptGetArg(popt_context))) usage(popt_context, EXIT_FAILURE, _("Argument missing."), poptGetInvocationName(popt_context)); diff --git a/src/veritysetup.c b/src/veritysetup.c index 7a4f4abd..c2fde06e 100644 --- a/src/veritysetup.c +++ b/src/veritysetup.c @@ -41,8 +41,6 @@ static int opt_ignore_corruption = 0; static int opt_ignore_zero_blocks = 0; static int opt_check_at_most_once = 0; -static int opt_version_mode = 0; - static const char **action_argv; static int action_argc; @@ -392,6 +390,11 @@ static void help(poptContext popt_context, DEFAULT_VERITY_HASH, DEFAULT_VERITY_DATA_BLOCK, DEFAULT_VERITY_HASH_BLOCK, DEFAULT_VERITY_SALT_SIZE, 1); + poptFreeContext(popt_context); + exit(EXIT_SUCCESS); + } else if (key->shortName == 'V') { + log_std("%s %s\n", PACKAGE_VERITY, PACKAGE_VERSION); + poptFreeContext(popt_context); exit(EXIT_SUCCESS); } else usage(popt_context, EXIT_SUCCESS, NULL, NULL); @@ -417,11 +420,11 @@ int main(int argc, const char **argv) { NULL, '\0', POPT_ARG_CALLBACK, help, 0, NULL, NULL }, { "help", '?', POPT_ARG_NONE, NULL, 0, N_("Show this help message"), NULL }, { "usage", '\0', POPT_ARG_NONE, NULL, 0, N_("Display brief usage"), NULL }, + { "version",'V', POPT_ARG_NONE, NULL, 0, N_("Print package version"), NULL }, POPT_TABLEEND }; static struct poptOption popt_options[] = { { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_help_options, 0, N_("Help options:"), NULL }, - { "version", '\0', POPT_ARG_NONE, &opt_version_mode, 0, N_("Print package version"), NULL }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL }, { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL }, { "no-superblock", 0, POPT_ARG_VAL, &use_superblock, 0, N_("Do not use verity superblock"), NULL }, @@ -489,12 +492,6 @@ int main(int argc, const char **argv) usage(popt_context, EXIT_FAILURE, poptStrerror(r), poptBadOption(popt_context, POPT_BADOPTION_NOALIAS)); - if (opt_version_mode) { - log_std("%s %s\n", PACKAGE_VERITY, PACKAGE_VERSION); - poptFreeContext(popt_context); - exit(EXIT_SUCCESS); - } - if (!(aname = poptGetArg(popt_context))) usage(popt_context, EXIT_FAILURE, _("Argument missing."), poptGetInvocationName(popt_context));