commit bfdfaae0405aa683cdae85bde58da742f4b59ae5 Author: Nick Mathewson <ni...@torproject.org> Date: Tue Oct 8 13:13:31 2019 -0400
Move responsibility for setting the "quiet level" into a table. Previously this was done with a big list of options in main.c which implied "hush" or "quiet". One of these options ("--digests") no longer existed, but we still checked for it. Now we use the table of command-line-only arguments to set this value. --- src/app/config/config.c | 35 +++++++++++++++++++++++++---------- src/app/config/config.h | 3 +++ src/app/main/main.c | 30 ++++++------------------------ 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/app/config/config.c b/src/app/config/config.c index 734bd0f92..ea6a5e233 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -2459,6 +2459,8 @@ static const struct { takes_argument_t takes_argument; /** If not CMD_RUN_TOR, what should Tor do when it starts? */ tor_cmdline_mode_t command; + /** If nonzero, set the quiet level to this. 1 is "hush", 2 is "quiet" */ + int quiet; } CMDLINE_ONLY_OPTIONS[] = { { .name="-f", .takes_argument=ARGUMENT_NECESSARY }, @@ -2467,10 +2469,12 @@ static const struct { .takes_argument=ARGUMENT_NECESSARY }, { .name="--hash-password", .takes_argument=ARGUMENT_NECESSARY, - .command=CMD_HASH_PASSWORD }, + .command=CMD_HASH_PASSWORD, + .quiet=1 }, { .name="--dump-config", .takes_argument=ARGUMENT_OPTIONAL, - .command=CMD_DUMP_CONFIG }, + .command=CMD_DUMP_CONFIG, + .quiet=2 }, { .name="--list-fingerprint", .command=CMD_LIST_FINGERPRINT }, { .name="--keygen", @@ -2485,20 +2489,28 @@ static const struct { { .name="--verify-config", .command=CMD_VERIFY_CONFIG }, { .name="--ignore-missing-torrc" }, - { .name="--quiet" }, - { .name="--hush" }, + { .name="--quiet", + .quiet=2 }, + { .name="--hush", + .quiet=1 }, { .name="--version", - .command=CMD_OTHER }, + .command=CMD_OTHER, + .quiet=1 }, { .name="--list-modules", - .command=CMD_OTHER }, + .command=CMD_OTHER, + .quiet=1 }, { .name="--library-versions", - .command=CMD_OTHER }, + .command=CMD_OTHER, + .quiet=1 }, { .name="-h", - .command=CMD_OTHER }, + .command=CMD_OTHER, + .quiet=1 }, { .name="--help", - .command=CMD_OTHER }, + .command=CMD_OTHER, + .quiet=1 }, { .name="--list-torrc-options", - .command=CMD_OTHER }, + .command=CMD_OTHER, + .quiet=1 }, { .name="--list-deprecated-options", .command=CMD_OTHER }, { .name="--nt-service" }, @@ -2541,6 +2553,9 @@ config_parse_commandline(int argc, char **argv, int ignore_errors) is_a_command = true; result->command = CMDLINE_ONLY_OPTIONS[j].command; } + int quiet = CMDLINE_ONLY_OPTIONS[j].quiet; + if (quiet > result->quiet_level) + result->quiet_level = quiet; break; } } diff --git a/src/app/config/config.h b/src/app/config/config.h index 582b97d74..8fc10d504 100644 --- a/src/app/config/config.h +++ b/src/app/config/config.h @@ -208,6 +208,9 @@ typedef struct { tor_cmdline_mode_t command; /** Argument for the command mode, if any. */ const char *command_arg; + /** How quiet have we been told to be? 1 for "hush", and 2 for "quiet". + */ + int quiet_level; } parsed_cmdline_t; parsed_cmdline_t *config_parse_commandline(int argc, char **argv, diff --git a/src/app/main/main.c b/src/app/main/main.c index ad8253cc7..95dccbee6 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -547,40 +547,22 @@ tor_init(int argc, char *argv[]) hs_init(); { - /* We search for the "quiet" option first, since it decides whether we - * will log anything at all to the command line. */ + /* We check for the "quiet"/"hush" settings first, since they decide + whether we log anything at all to stdout. */ parsed_cmdline_t *cmdline; - const config_line_t *cl = NULL; cmdline = config_parse_commandline(argc, argv, 1); - if (cmdline != NULL) { - cl = cmdline->cmdline_opts; - } - for (; cl; cl = cl->next) { - if (!strcmp(cl->key, "--hush")) - quiet = 1; - if (!strcmp(cl->key, "--quiet") || - !strcmp(cl->key, "--dump-config")) - quiet = 2; - /* The following options imply --hush */ - if (!strcmp(cl->key, "--version") || !strcmp(cl->key, "--digests") || - !strcmp(cl->key, "--list-torrc-options") || - !strcmp(cl->key, "--library-versions") || - !strcmp(cl->key, "--list-modules") || - !strcmp(cl->key, "--hash-password") || - !strcmp(cl->key, "-h") || !strcmp(cl->key, "--help")) { - if (quiet < 1) - quiet = 1; - } - } + if (cmdline) + quiet = cmdline->quiet_level; parsed_cmdline_free(cmdline); } /* give it somewhere to log to initially */ switch (quiet) { case 2: - /* no initial logging */ + /* --quiet: no initial logging */ break; case 1: + /* --hush: log at warning or higher. */ add_temp_log(LOG_WARN); break; default: _______________________________________________ tor-commits mailing list tor-commits@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits