]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Move code to add default log into quiet_level.c
authorNick Mathewson <nickm@torproject.org>
Thu, 17 Oct 2019 16:48:39 +0000 (12:48 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 17 Oct 2019 16:48:39 +0000 (12:48 -0400)
I'm about to unify the code for handling this between main.c and
config.c.

src/app/config/quiet_level.c [new file with mode: 0644]
src/app/config/quiet_level.h
src/app/main/main.c
src/core/include.am

diff --git a/src/app/config/quiet_level.c b/src/app/config/quiet_level.c
new file mode 100644 (file)
index 0000000..f00d6b5
--- /dev/null
@@ -0,0 +1,33 @@
+/* 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 */
+
+#include "orconfig.h"
+#include "lib/log/log.h"
+#include "app/config/quiet_level.h"
+
+/** 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.
+ */
+quiet_level_t quiet_level = 0;
+
+/** Add a default log (or not), depending on the value of <b>quiet</b>. */
+void
+add_default_log_for_quiet_level(quiet_level_t quiet)
+{
+  switch (quiet) {
+    case QUIET_SILENT:
+      /* --quiet: no initial logging */
+      return;
+    case QUIET_HUSH:
+    /* --hush: log at warning or higher. */
+      add_default_log(LOG_WARN);
+      break;
+    case QUIET_NONE: /* fall through */
+    default:
+      add_default_log(LOG_NOTICE);
+  }
+}
index e90ec3f276128827c0167cfd124dec42855f283f..03e3f58fb08c9b9c5f3543283b44d646c7f47e36 100644 (file)
@@ -25,4 +25,6 @@ typedef enum {
 /** How quietly should Tor log at startup? */
 extern quiet_level_t quiet_level;
 
+void add_default_log_for_quiet_level(quiet_level_t quiet);
+
 #endif /* !defined(QUIET_LEVEL_H) */
index e6bd4f30b22969be4e6548298ae70804f3c54813..fad2e0b62fa95ef9db12f13e259e46391a515de5 100644 (file)
@@ -109,16 +109,6 @@ static void dumpmemusage(int severity);
 static void dumpstats(int severity); /* log stats */
 static void process_signal(int sig);
 
-/********* START VARIABLES **********/
-
-/** 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.
- */
-quiet_level_t quiet_level = 0;
-
-/********* END VARIABLES ************/
-
 /** Called when we get a SIGHUP: reload configuration files and keys,
  * retry all connections, and so on. */
 static int
@@ -558,18 +548,7 @@ tor_init(int argc, char *argv[])
   }
 
  /* give it somewhere to log to initially */
-  switch (quiet) {
-    case QUIET_SILENT:
-      /* --quiet: no initial logging */
-      break;
-    case QUIET_HUSH:
-      /* --hush: log at warning or higher. */
-      add_default_log(LOG_WARN);
-      break;
-    case QUIET_NONE: /* fall through */
-    default:
-      add_default_log(LOG_NOTICE);
-  }
+  add_default_log_for_quiet_level(quiet);
   quiet_level = quiet;
 
   {
index f6ae3f2b51610a4e4111aa3c157352a16236d3c9..fb2f93d81edc702dcceb062c79d20fcb5fc79026 100644 (file)
@@ -9,6 +9,7 @@ endif
 # ADD_C_FILE: INSERT SOURCES HERE.
 LIBTOR_APP_A_SOURCES =                                 \
        src/app/config/config.c                 \
+       src/app/config/quiet_level.c            \
        src/app/config/statefile.c              \
        src/app/main/main.c                     \
        src/app/main/shutdown.c                 \