mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +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",
|
{ .name="--hash-password",
|
||||||
.takes_argument=ARGUMENT_NECESSARY,
|
.takes_argument=ARGUMENT_NECESSARY,
|
||||||
.command=CMD_HASH_PASSWORD,
|
.command=CMD_HASH_PASSWORD,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--dump-config",
|
{ .name="--dump-config",
|
||||||
.takes_argument=ARGUMENT_OPTIONAL,
|
.takes_argument=ARGUMENT_OPTIONAL,
|
||||||
.command=CMD_DUMP_CONFIG,
|
.command=CMD_DUMP_CONFIG,
|
||||||
.quiet=2 },
|
.quiet=QUIET_SILENT },
|
||||||
{ .name="--list-fingerprint",
|
{ .name="--list-fingerprint",
|
||||||
.command=CMD_LIST_FINGERPRINT },
|
.command=CMD_LIST_FINGERPRINT },
|
||||||
{ .name="--keygen",
|
{ .name="--keygen",
|
||||||
@ -2490,27 +2490,27 @@ static const struct {
|
|||||||
.command=CMD_VERIFY_CONFIG },
|
.command=CMD_VERIFY_CONFIG },
|
||||||
{ .name="--ignore-missing-torrc" },
|
{ .name="--ignore-missing-torrc" },
|
||||||
{ .name="--quiet",
|
{ .name="--quiet",
|
||||||
.quiet=2 },
|
.quiet=QUIET_SILENT },
|
||||||
{ .name="--hush",
|
{ .name="--hush",
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--version",
|
{ .name="--version",
|
||||||
.command=CMD_IMMEDIATE,
|
.command=CMD_IMMEDIATE,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--list-modules",
|
{ .name="--list-modules",
|
||||||
.command=CMD_IMMEDIATE,
|
.command=CMD_IMMEDIATE,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--library-versions",
|
{ .name="--library-versions",
|
||||||
.command=CMD_IMMEDIATE,
|
.command=CMD_IMMEDIATE,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="-h",
|
{ .name="-h",
|
||||||
.command=CMD_IMMEDIATE,
|
.command=CMD_IMMEDIATE,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--help",
|
{ .name="--help",
|
||||||
.command=CMD_IMMEDIATE,
|
.command=CMD_IMMEDIATE,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--list-torrc-options",
|
{ .name="--list-torrc-options",
|
||||||
.command=CMD_IMMEDIATE,
|
.command=CMD_IMMEDIATE,
|
||||||
.quiet=1 },
|
.quiet=QUIET_HUSH },
|
||||||
{ .name="--list-deprecated-options",
|
{ .name="--list-deprecated-options",
|
||||||
.command=CMD_IMMEDIATE },
|
.command=CMD_IMMEDIATE },
|
||||||
{ .name="--nt-service" },
|
{ .name="--nt-service" },
|
||||||
@ -2553,7 +2553,7 @@ 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;
|
quiet_level_t quiet = CMDLINE_ONLY_OPTIONS[j].quiet;
|
||||||
if (quiet > result->quiet_level)
|
if (quiet > result->quiet_level)
|
||||||
result->quiet_level = quiet;
|
result->quiet_level = quiet;
|
||||||
break;
|
break;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "app/config/or_options_st.h"
|
#include "app/config/or_options_st.h"
|
||||||
#include "lib/testsupport/testsupport.h"
|
#include "lib/testsupport/testsupport.h"
|
||||||
|
#include "app/config/quiet_level.h"
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(DARWIN)
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(DARWIN)
|
||||||
#define KERNEL_MAY_SUPPORT_IPFW
|
#define KERNEL_MAY_SUPPORT_IPFW
|
||||||
@ -208,9 +209,8 @@ 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".
|
/** How quiet have we been told to be? */
|
||||||
*/
|
quiet_level_t quiet_level;
|
||||||
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,
|
||||||
|
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/config.h"
|
||||||
#include "app/config/statefile.h"
|
#include "app/config/statefile.h"
|
||||||
|
#include "app/config/quiet_level.h"
|
||||||
#include "app/main/main.h"
|
#include "app/main/main.h"
|
||||||
#include "app/main/ntmain.h"
|
#include "app/main/ntmain.h"
|
||||||
#include "app/main/shutdown.h"
|
#include "app/main/shutdown.h"
|
||||||
@ -110,11 +111,11 @@ static void process_signal(int sig);
|
|||||||
|
|
||||||
/********* START VARIABLES **********/
|
/********* START VARIABLES **********/
|
||||||
|
|
||||||
/** Decides our behavior when no logs are configured/before any
|
/** Decides our behavior when no logs are configured/before any logs have been
|
||||||
* logs have been configured. For 0, we log notice to stdout as normal.
|
* configured. For QUIET_NONE, we log notice to stdout as normal. For
|
||||||
* For 1, we log warnings only. For 2, we log nothing.
|
* QUIET_HUSH, we log warnings only. For QUIET_SILENT, we log nothing.
|
||||||
*/
|
*/
|
||||||
int quiet_level = 0;
|
quiet_level_t quiet_level = 0;
|
||||||
|
|
||||||
/********* END VARIABLES ************/
|
/********* END VARIABLES ************/
|
||||||
|
|
||||||
@ -528,7 +529,7 @@ int
|
|||||||
tor_init(int argc, char *argv[])
|
tor_init(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char progname[256];
|
char progname[256];
|
||||||
int quiet = 0;
|
quiet_level_t quiet = QUIET_NONE;
|
||||||
|
|
||||||
time_of_process_start = time(NULL);
|
time_of_process_start = time(NULL);
|
||||||
tor_init_connection_lists();
|
tor_init_connection_lists();
|
||||||
@ -558,13 +559,14 @@ tor_init(int argc, char *argv[])
|
|||||||
|
|
||||||
/* give it somewhere to log to initially */
|
/* give it somewhere to log to initially */
|
||||||
switch (quiet) {
|
switch (quiet) {
|
||||||
case 2:
|
case QUIET_SILENT:
|
||||||
/* --quiet: no initial logging */
|
/* --quiet: no initial logging */
|
||||||
break;
|
break;
|
||||||
case 1:
|
case QUIET_HUSH:
|
||||||
/* --hush: log at warning or higher. */
|
/* --hush: log at warning or higher. */
|
||||||
add_temp_log(LOG_WARN);
|
add_temp_log(LOG_WARN);
|
||||||
break;
|
break;
|
||||||
|
case QUIET_NONE: /* fall through */
|
||||||
default:
|
default:
|
||||||
add_temp_log(LOG_NOTICE);
|
add_temp_log(LOG_NOTICE);
|
||||||
}
|
}
|
||||||
@ -1331,7 +1333,7 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
|
|||||||
result = 0;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
case CMD_VERIFY_CONFIG:
|
case CMD_VERIFY_CONFIG:
|
||||||
if (quiet_level == 0)
|
if (quiet_level == QUIET_NONE)
|
||||||
printf("Configuration was valid\n");
|
printf("Configuration was valid\n");
|
||||||
result = 0;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -215,6 +215,7 @@ noinst_HEADERS += \
|
|||||||
src/app/config/config.h \
|
src/app/config/config.h \
|
||||||
src/app/config/or_options_st.h \
|
src/app/config/or_options_st.h \
|
||||||
src/app/config/or_state_st.h \
|
src/app/config/or_state_st.h \
|
||||||
|
src/app/config/quiet_level.h \
|
||||||
src/app/config/statefile.h \
|
src/app/config/statefile.h \
|
||||||
src/app/config/tor_cmdline_mode.h \
|
src/app/config/tor_cmdline_mode.h \
|
||||||
src/app/main/main.h \
|
src/app/main/main.h \
|
||||||
|
@ -94,7 +94,6 @@ void tor_mainloop_free_all(void);
|
|||||||
struct token_bucket_rw_t;
|
struct token_bucket_rw_t;
|
||||||
|
|
||||||
extern time_t time_of_process_start;
|
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_bucket;
|
||||||
extern struct token_bucket_rw_t global_relayed_bucket;
|
extern struct token_bucket_rw_t global_relayed_bucket;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user