mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
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:
parent
c529b3f8f1
commit
bfdfaae040
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user