From ad54c197a97ba71129a8d223c1dae665e19b9d8f Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 6 Apr 2015 21:01:43 +0300 Subject: [PATCH 1/3] Fix error message in do_dump_config(). --- src/or/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/or/main.c b/src/or/main.c index a816fad2bb..c0ca1584a3 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -2803,6 +2803,7 @@ do_dump_config(void) const char *arg = options->command_arg; int how; char *opts; + if (!strcmp(arg, "short")) { how = OPTIONS_DUMP_MINIMAL; } else if (!strcmp(arg, "non-builtin")) { @@ -2810,8 +2811,9 @@ do_dump_config(void) } else if (!strcmp(arg, "full")) { how = OPTIONS_DUMP_ALL; } else { - fprintf(stderr, "%s is not a recognized argument to --dump-config. " - "Please select 'short', 'non-builtin', or 'full'", arg); + fprintf(stderr, "No recognizable option to --dump-config found!\n"); + fprintf(stderr, "Please select 'short', 'non-builtin', or 'full'.\n"); + return -1; } From e89c200c47fdb6253ee99d3603e86a8f1bdbab8c Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 6 Apr 2015 21:36:55 +0300 Subject: [PATCH 2/3] Print the error message for --dump-config even if no arguments are given. --- changes/bug15541 | 5 +++++ src/or/config.c | 21 ++++++++++++++++----- src/or/main.c | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 changes/bug15541 diff --git a/changes/bug15541 b/changes/bug15541 new file mode 100644 index 0000000000..f73ce5f4d4 --- /dev/null +++ b/changes/bug15541 @@ -0,0 +1,5 @@ + o Minor bugfixes (interface): + - Print usage information for --dump-config when it is used without + an argument. Also, fix the error message to use different wording + and add newline at the end. Fixes bug 15541; bugfix on 0.2.5.1-alpha. + diff --git a/src/or/config.c b/src/or/config.c index d65d35dfc2..ddd20ee889 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1868,15 +1868,21 @@ options_act(const or_options_t *old_options) return 0; } +typedef enum { + TAKES_NO_ARGUMENT = 0, + ARGUMENT_NECESSARY = 1, + ARGUMENT_OPTIONAL = 2 +} takes_argument_t; + static const struct { const char *name; - int takes_argument; + takes_argument_t takes_argument; } CMDLINE_ONLY_OPTIONS[] = { { "-f", 1 }, { "--allow-missing-torrc", 0 }, { "--defaults-torrc", 1 }, { "--hash-password", 1 }, - { "--dump-config", 1 }, + { "--dump-config", ARGUMENT_OPTIONAL }, { "--list-fingerprint", 0 }, { "--verify-config", 0 }, { "--ignore-missing-torrc", 0 }, @@ -1915,7 +1921,7 @@ config_parse_commandline(int argc, char **argv, int ignore_errors, while (i < argc) { unsigned command = CONFIG_LINE_NORMAL; - int want_arg = 1; + takes_argument_t want_arg = ARGUMENT_NECESSARY; int is_cmdline = 0; int j; @@ -1945,7 +1951,9 @@ config_parse_commandline(int argc, char **argv, int ignore_errors, want_arg = 0; } - if (want_arg && i == argc-1) { + const int is_last = (i == argc-1); + + if (want_arg == ARGUMENT_NECESSARY && is_last) { if (ignore_errors) { arg = strdup(""); } else { @@ -1955,8 +1963,11 @@ config_parse_commandline(int argc, char **argv, int ignore_errors, config_free_lines(front_cmdline); return -1; } + } else if (want_arg == ARGUMENT_OPTIONAL && is_last) { + arg = tor_strdup(""); } else { - arg = want_arg ? tor_strdup(argv[i+1]) : strdup(""); + arg = (want_arg != TAKES_NO_ARGUMENT) ? tor_strdup(argv[i+1]) : + tor_strdup(""); } param = tor_malloc_zero(sizeof(config_line_t)); diff --git a/src/or/main.c b/src/or/main.c index c0ca1584a3..a3da148023 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -2811,7 +2811,7 @@ do_dump_config(void) } else if (!strcmp(arg, "full")) { how = OPTIONS_DUMP_ALL; } else { - fprintf(stderr, "No recognizable option to --dump-config found!\n"); + fprintf(stderr, "No valid argument to --dump-config found!\n"); fprintf(stderr, "Please select 'short', 'non-builtin', or 'full'.\n"); return -1; From 6b0c443dde31f57f00c36ef4d53bd85bdfef8d79 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 6 Apr 2015 22:05:27 +0300 Subject: [PATCH 3/3] Update other entries in CMDLINE_ONLY_OPTIONS to use values from takes_argument_t. --- src/or/config.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/or/config.c b/src/or/config.c index ddd20ee889..825bd18b16 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1878,23 +1878,23 @@ static const struct { const char *name; takes_argument_t takes_argument; } CMDLINE_ONLY_OPTIONS[] = { - { "-f", 1 }, - { "--allow-missing-torrc", 0 }, - { "--defaults-torrc", 1 }, - { "--hash-password", 1 }, + { "-f", ARGUMENT_NECESSARY }, + { "--allow-missing-torrc", TAKES_NO_ARGUMENT }, + { "--defaults-torrc", ARGUMENT_NECESSARY }, + { "--hash-password", ARGUMENT_NECESSARY }, { "--dump-config", ARGUMENT_OPTIONAL }, - { "--list-fingerprint", 0 }, - { "--verify-config", 0 }, - { "--ignore-missing-torrc", 0 }, - { "--quiet", 0 }, - { "--hush", 0 }, - { "--version", 0 }, - { "--library-versions", 0 }, - { "-h", 0 }, - { "--help", 0 }, - { "--list-torrc-options", 0 }, - { "--nt-service", 0 }, - { "-nt-service", 0 }, + { "--list-fingerprint", TAKES_NO_ARGUMENT }, + { "--verify-config", TAKES_NO_ARGUMENT }, + { "--ignore-missing-torrc", TAKES_NO_ARGUMENT }, + { "--quiet", TAKES_NO_ARGUMENT }, + { "--hush", TAKES_NO_ARGUMENT }, + { "--version", TAKES_NO_ARGUMENT }, + { "--library-versions", TAKES_NO_ARGUMENT }, + { "-h", TAKES_NO_ARGUMENT }, + { "--help", TAKES_NO_ARGUMENT }, + { "--list-torrc-options", TAKES_NO_ARGUMENT }, + { "--nt-service", TAKES_NO_ARGUMENT }, + { "-nt-service", TAKES_NO_ARGUMENT }, { NULL, 0 }, };