commit d97d7f0e48495e0b354b30b79992da822d12c15d
Author: Nick Mathewson <ni...@torproject.org>
Date:   Wed Oct 16 16:49:54 2019 -0400

    Use an enum for quiet_level.
---
 src/app/config/config.c      | 22 +++++++++++-----------
 src/app/config/config.h      |  6 +++---
 src/app/config/quiet_level.h | 28 ++++++++++++++++++++++++++++
 src/app/main/main.c          | 18 ++++++++++--------
 src/core/include.am          |  1 +
 src/core/mainloop/mainloop.h |  1 -
 6 files changed, 53 insertions(+), 23 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 522c3b572..37eab2291 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -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;
diff --git a/src/app/config/config.h b/src/app/config/config.h
index 8fc10d504..e5b687c31 100644
--- a/src/app/config/config.h
+++ b/src/app/config/config.h
@@ -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,
diff --git a/src/app/config/quiet_level.h b/src/app/config/quiet_level.h
new file mode 100644
index 000000000..e90ec3f27
--- /dev/null
+++ b/src/app/config/quiet_level.h
@@ -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) */
diff --git a/src/app/main/main.c b/src/app/main/main.c
index 22694fdbb..2d7579336 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -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;
diff --git a/src/core/include.am b/src/core/include.am
index 64004da34..92fb2c213 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -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                             \
diff --git a/src/core/mainloop/mainloop.h b/src/core/mainloop/mainloop.h
index caef736c1..fe181c192 100644
--- a/src/core/mainloop/mainloop.h
+++ b/src/core/mainloop/mainloop.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;
 



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to