Browse Source

Turn the logging code into a subsystem

Nick Mathewson 5 years ago
parent
commit
d3e4afcc9b

+ 0 - 3
src/app/main/main.c

@@ -819,9 +819,7 @@ tor_free_all(int postfork)
 
   /* Stuff in util.c and address.c*/
   if (!postfork) {
-    escaped(NULL);
     esc_router_info(NULL);
-    logs_free_all(); /* free log strings. do this last so logs keep working. */
   }
 }
 
@@ -1398,7 +1396,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
 
   update_approx_time(time(NULL));
   tor_compress_init();
-  init_logging(0);
   monotime_init();
 
   int argc = tor_cfg->argc + tor_cfg->argc_owned;

+ 2 - 0
src/app/main/subsystem_list.c

@@ -11,6 +11,7 @@
 #include "lib/err/torerr_sys.h"
 #include "lib/process/winprocess_sys.h"
 #include "lib/thread/thread_sys.h"
+#include "lib/log/log_sys.h"
 
 #include <stddef.h>
 
@@ -21,6 +22,7 @@ const subsys_fns_t *tor_subsystems[] = {
   &sys_winprocess,
   &sys_torerr,
   &sys_threads,
+  &sys_logging,
 };
 
 const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems);

+ 1 - 0
src/lib/log/.may_include

@@ -9,6 +9,7 @@ lib/lock/*.h
 lib/log/*.h
 lib/malloc/*.h
 lib/string/*.h
+lib/subsys/*.h
 lib/testsupport/*.h
 lib/version/*.h
 lib/wallclock/*.h

+ 2 - 0
src/lib/log/include.am

@@ -9,6 +9,7 @@ src_lib_libtor_log_a_SOURCES =			\
 	src/lib/log/escape.c			\
 	src/lib/log/ratelim.c			\
 	src/lib/log/log.c			\
+	src/lib/log/log_sys.c			\
 	src/lib/log/util_bug.c
 
 if WIN32
@@ -24,5 +25,6 @@ noinst_HEADERS +=					\
 	src/lib/log/escape.h				\
 	src/lib/log/ratelim.h				\
 	src/lib/log/log.h				\
+	src/lib/log/log_sys.h				\
 	src/lib/log/util_bug.h				\
 	src/lib/log/win32err.h

+ 1 - 0
src/lib/log/log.c

@@ -32,6 +32,7 @@
 
 #define LOG_PRIVATE
 #include "lib/log/log.h"
+#include "lib/log/log_sys.h"
 #include "lib/version/git_revision.h"
 #include "lib/log/ratelim.h"
 #include "lib/lock/compat_mutex.h"

+ 35 - 0
src/lib/log/log_sys.c

@@ -0,0 +1,35 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file log_sys.c
+ * \brief Setup and tear down the logging module.
+ **/
+
+#include "orconfig.h"
+#include "lib/subsys/subsys.h"
+#include "lib/log/escape.h"
+#include "lib/log/log.h"
+#include "lib/log/log_sys.h"
+
+static int
+init_logging_subsys(void)
+{
+  init_logging(0);
+  return 0;
+}
+
+static void
+shutdown_logging_subsys(void)
+{
+  logs_free_all();
+  escaped(NULL);
+}
+
+const subsys_fns_t sys_logging = {
+  .name = "log",
+  .supported = true,
+  .level = -90,
+  .initialize = init_logging_subsys,
+  .shutdown = shutdown_logging_subsys,
+};

+ 14 - 0
src/lib/log/log_sys.h

@@ -0,0 +1,14 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file log_sys.h
+ * \brief Declare subsystem object for the logging module.
+ **/
+
+#ifndef TOR_LOG_SYS_H
+#define TOR_LOG_SYS_H
+
+extern const struct subsys_fns_t sys_logging;
+
+#endif /* !defined(TOR_LOG_SYS_H) */