mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Use an enum for quiet_level.
This commit is contained in:
parent
b9f002dec6
commit
d97d7f0e48
@ -2470,11 +2470,11 @@ static const struct {
|
||||
{ .name="--hash-password",
|
||||
.takes_argument=ARGUMENT_NECESSARY,
|
||||
.command=CMD_HASH_PASSWORD,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--dump-config",
|
||||
.takes_argument=ARGUMENT_OPTIONAL,
|
||||
.command=CMD_DUMP_CONFIG,
|
||||
.quiet=2 },
|
||||
.quiet=QUIET_SILENT },
|
||||
{ .name="--list-fingerprint",
|
||||
.command=CMD_LIST_FINGERPRINT },
|
||||
{ .name="--keygen",
|
||||
@ -2490,27 +2490,27 @@ static const struct {
|
||||
.command=CMD_VERIFY_CONFIG },
|
||||
{ .name="--ignore-missing-torrc" },
|
||||
{ .name="--quiet",
|
||||
.quiet=2 },
|
||||
.quiet=QUIET_SILENT },
|
||||
{ .name="--hush",
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--version",
|
||||
.command=CMD_IMMEDIATE,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--list-modules",
|
||||
.command=CMD_IMMEDIATE,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--library-versions",
|
||||
.command=CMD_IMMEDIATE,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="-h",
|
||||
.command=CMD_IMMEDIATE,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--help",
|
||||
.command=CMD_IMMEDIATE,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--list-torrc-options",
|
||||
.command=CMD_IMMEDIATE,
|
||||
.quiet=1 },
|
||||
.quiet=QUIET_HUSH },
|
||||
{ .name="--list-deprecated-options",
|
||||
.command=CMD_IMMEDIATE },
|
||||
{ .name="--nt-service" },
|
||||
@ -2553,7 +2553,7 @@ 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;
|
||||
quiet_level_t quiet = CMDLINE_ONLY_OPTIONS[j].quiet;
|
||||
if (quiet > result->quiet_level)
|
||||
result->quiet_level = quiet;
|
||||
break;
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "app/config/or_options_st.h"
|
||||
#include "lib/testsupport/testsupport.h"
|
||||
#include "app/config/quiet_level.h"
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(DARWIN)
|
||||
#define KERNEL_MAY_SUPPORT_IPFW
|
||||
@ -208,9 +209,8 @@ 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;
|
||||
/** How quiet have we been told to be? */
|
||||
quiet_level_t quiet_level;
|
||||
} parsed_cmdline_t;
|
||||
|
||||
parsed_cmdline_t *config_parse_commandline(int argc, char **argv,
|
||||
|
28
src/app/config/quiet_level.h
Normal file
28
src/app/config/quiet_level.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2001 Matej Pfajfar.
|
||||
* Copyright (c) 2001-2004, Roger Dingledine.
|
||||
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
||||
* Copyright (c) 2007-2019, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
/**
|
||||
* \file quiet_level.h
|
||||
* \brief Declare the quiet_level enumeration and global.
|
||||
**/
|
||||
|
||||
#ifndef QUIET_LEVEL_H
|
||||
#define QUIET_LEVEL_H
|
||||
|
||||
/** Enumeration to define how quietly Tor should log at startup. */
|
||||
typedef enum {
|
||||
/** Default quiet level: we log everything of level NOTICE or higher. */
|
||||
QUIET_NONE = 0,
|
||||
/** "--hush" quiet level: we log everything of level WARNING or higher. */
|
||||
QUIET_HUSH = 1 ,
|
||||
/** "--quiet" quiet level: we log nothing at all. */
|
||||
QUIET_SILENT = 2
|
||||
} quiet_level_t;
|
||||
|
||||
/** How quietly should Tor log at startup? */
|
||||
extern quiet_level_t quiet_level;
|
||||
|
||||
#endif /* !defined(QUIET_LEVEL_H) */
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "app/config/config.h"
|
||||
#include "app/config/statefile.h"
|
||||
#include "app/config/quiet_level.h"
|
||||
#include "app/main/main.h"
|
||||
#include "app/main/ntmain.h"
|
||||
#include "app/main/shutdown.h"
|
||||
@ -110,11 +111,11 @@ static void process_signal(int sig);
|
||||
|
||||
/********* START VARIABLES **********/
|
||||
|
||||
/** Decides our behavior when no logs are configured/before any
|
||||
* logs have been configured. For 0, we log notice to stdout as normal.
|
||||
* For 1, we log warnings only. For 2, we log nothing.
|
||||
/** Decides our behavior when no logs are configured/before any logs have been
|
||||
* configured. For QUIET_NONE, we log notice to stdout as normal. For
|
||||
* QUIET_HUSH, we log warnings only. For QUIET_SILENT, we log nothing.
|
||||
*/
|
||||
int quiet_level = 0;
|
||||
quiet_level_t quiet_level = 0;
|
||||
|
||||
/********* END VARIABLES ************/
|
||||
|
||||
@ -528,7 +529,7 @@ int
|
||||
tor_init(int argc, char *argv[])
|
||||
{
|
||||
char progname[256];
|
||||
int quiet = 0;
|
||||
quiet_level_t quiet = QUIET_NONE;
|
||||
|
||||
time_of_process_start = time(NULL);
|
||||
tor_init_connection_lists();
|
||||
@ -558,13 +559,14 @@ tor_init(int argc, char *argv[])
|
||||
|
||||
/* give it somewhere to log to initially */
|
||||
switch (quiet) {
|
||||
case 2:
|
||||
case QUIET_SILENT:
|
||||
/* --quiet: no initial logging */
|
||||
break;
|
||||
case 1:
|
||||
case QUIET_HUSH:
|
||||
/* --hush: log at warning or higher. */
|
||||
add_temp_log(LOG_WARN);
|
||||
break;
|
||||
case QUIET_NONE: /* fall through */
|
||||
default:
|
||||
add_temp_log(LOG_NOTICE);
|
||||
}
|
||||
@ -1331,7 +1333,7 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
|
||||
result = 0;
|
||||
break;
|
||||
case CMD_VERIFY_CONFIG:
|
||||
if (quiet_level == 0)
|
||||
if (quiet_level == QUIET_NONE)
|
||||
printf("Configuration was valid\n");
|
||||
result = 0;
|
||||
break;
|
||||
|
@ -215,6 +215,7 @@ noinst_HEADERS += \
|
||||
src/app/config/config.h \
|
||||
src/app/config/or_options_st.h \
|
||||
src/app/config/or_state_st.h \
|
||||
src/app/config/quiet_level.h \
|
||||
src/app/config/statefile.h \
|
||||
src/app/config/tor_cmdline_mode.h \
|
||||
src/app/main/main.h \
|
||||
|
@ -94,7 +94,6 @@ void tor_mainloop_free_all(void);
|
||||
struct token_bucket_rw_t;
|
||||
|
||||
extern time_t time_of_process_start;
|
||||
extern int quiet_level;
|
||||
extern struct token_bucket_rw_t global_bucket;
|
||||
extern struct token_bucket_rw_t global_relayed_bucket;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user