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.
This commit is contained in:
Nick Mathewson 2019-10-08 13:13:31 -04:00
parent c529b3f8f1
commit bfdfaae040
3 changed files with 34 additions and 34 deletions

View File

@ -2459,6 +2459,8 @@ static const struct {
takes_argument_t takes_argument; takes_argument_t takes_argument;
/** If not CMD_RUN_TOR, what should Tor do when it starts? */ /** If not CMD_RUN_TOR, what should Tor do when it starts? */
tor_cmdline_mode_t command; tor_cmdline_mode_t command;
/** If nonzero, set the quiet level to this. 1 is "hush", 2 is "quiet" */
int quiet;
} CMDLINE_ONLY_OPTIONS[] = { } CMDLINE_ONLY_OPTIONS[] = {
{ .name="-f", { .name="-f",
.takes_argument=ARGUMENT_NECESSARY }, .takes_argument=ARGUMENT_NECESSARY },
@ -2467,10 +2469,12 @@ static const struct {
.takes_argument=ARGUMENT_NECESSARY }, .takes_argument=ARGUMENT_NECESSARY },
{ .name="--hash-password", { .name="--hash-password",
.takes_argument=ARGUMENT_NECESSARY, .takes_argument=ARGUMENT_NECESSARY,
.command=CMD_HASH_PASSWORD }, .command=CMD_HASH_PASSWORD,
.quiet=1 },
{ .name="--dump-config", { .name="--dump-config",
.takes_argument=ARGUMENT_OPTIONAL, .takes_argument=ARGUMENT_OPTIONAL,
.command=CMD_DUMP_CONFIG }, .command=CMD_DUMP_CONFIG,
.quiet=2 },
{ .name="--list-fingerprint", { .name="--list-fingerprint",
.command=CMD_LIST_FINGERPRINT }, .command=CMD_LIST_FINGERPRINT },
{ .name="--keygen", { .name="--keygen",
@ -2485,20 +2489,28 @@ static const struct {
{ .name="--verify-config", { .name="--verify-config",
.command=CMD_VERIFY_CONFIG }, .command=CMD_VERIFY_CONFIG },
{ .name="--ignore-missing-torrc" }, { .name="--ignore-missing-torrc" },
{ .name="--quiet" }, { .name="--quiet",
{ .name="--hush" }, .quiet=2 },
{ .name="--hush",
.quiet=1 },
{ .name="--version", { .name="--version",
.command=CMD_OTHER }, .command=CMD_OTHER,
.quiet=1 },
{ .name="--list-modules", { .name="--list-modules",
.command=CMD_OTHER }, .command=CMD_OTHER,
.quiet=1 },
{ .name="--library-versions", { .name="--library-versions",
.command=CMD_OTHER }, .command=CMD_OTHER,
.quiet=1 },
{ .name="-h", { .name="-h",
.command=CMD_OTHER }, .command=CMD_OTHER,
.quiet=1 },
{ .name="--help", { .name="--help",
.command=CMD_OTHER }, .command=CMD_OTHER,
.quiet=1 },
{ .name="--list-torrc-options", { .name="--list-torrc-options",
.command=CMD_OTHER }, .command=CMD_OTHER,
.quiet=1 },
{ .name="--list-deprecated-options", { .name="--list-deprecated-options",
.command=CMD_OTHER }, .command=CMD_OTHER },
{ .name="--nt-service" }, { .name="--nt-service" },
@ -2541,6 +2553,9 @@ config_parse_commandline(int argc, char **argv, int ignore_errors)
is_a_command = true; is_a_command = true;
result->command = CMDLINE_ONLY_OPTIONS[j].command; result->command = CMDLINE_ONLY_OPTIONS[j].command;
} }
int quiet = CMDLINE_ONLY_OPTIONS[j].quiet;
if (quiet > result->quiet_level)
result->quiet_level = quiet;
break; break;
} }
} }

View File

@ -208,6 +208,9 @@ typedef struct {
tor_cmdline_mode_t command; tor_cmdline_mode_t command;
/** Argument for the command mode, if any. */ /** Argument for the command mode, if any. */
const char *command_arg; 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;
parsed_cmdline_t *config_parse_commandline(int argc, char **argv, parsed_cmdline_t *config_parse_commandline(int argc, char **argv,

View File

@ -547,40 +547,22 @@ tor_init(int argc, char *argv[])
hs_init(); hs_init();
{ {
/* We search for the "quiet" option first, since it decides whether we /* We check for the "quiet"/"hush" settings first, since they decide
* will log anything at all to the command line. */ whether we log anything at all to stdout. */
parsed_cmdline_t *cmdline; parsed_cmdline_t *cmdline;
const config_line_t *cl = NULL;
cmdline = config_parse_commandline(argc, argv, 1); cmdline = config_parse_commandline(argc, argv, 1);
if (cmdline != NULL) { if (cmdline)
cl = cmdline->cmdline_opts; quiet = cmdline->quiet_level;
}
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;
}
}
parsed_cmdline_free(cmdline); parsed_cmdline_free(cmdline);
} }
/* give it somewhere to log to initially */ /* give it somewhere to log to initially */
switch (quiet) { switch (quiet) {
case 2: case 2:
/* no initial logging */ /* --quiet: no initial logging */
break; break;
case 1: case 1:
/* --hush: log at warning or higher. */
add_temp_log(LOG_WARN); add_temp_log(LOG_WARN);
break; break;
default: default: