[tor-commits] [tor/master] Turn the logging code into a subsystem

nickm at torproject.org nickm at torproject.org
Fri Nov 9 20:01:54 UTC 2018


commit d3e4afcc9b835e0f862207ef16d7e706ceea9ce1
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Nov 1 13:26:33 2018 -0400

    Turn the logging code into a subsystem
---
 src/app/main/main.c           |  3 ---
 src/app/main/subsystem_list.c |  2 ++
 src/lib/log/.may_include      |  1 +
 src/lib/log/include.am        |  2 ++
 src/lib/log/log.c             |  1 +
 src/lib/log/log_sys.c         | 35 +++++++++++++++++++++++++++++++++++
 src/lib/log/log_sys.h         | 14 ++++++++++++++
 7 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/src/app/main/main.c b/src/app/main/main.c
index 21a283278..f44f3475d 100644
--- a/src/app/main/main.c
+++ b/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;
diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c
index c3b731ca3..4a2994ec4 100644
--- a/src/app/main/subsystem_list.c
+++ b/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);
diff --git a/src/lib/log/.may_include b/src/lib/log/.may_include
index 7ca1863a5..11c87f0a0 100644
--- a/src/lib/log/.may_include
+++ b/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
diff --git a/src/lib/log/include.am b/src/lib/log/include.am
index c6f404e26..9d3dbe310 100644
--- a/src/lib/log/include.am
+++ b/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
diff --git a/src/lib/log/log.c b/src/lib/log/log.c
index bc7b36dcb..46107fe84 100644
--- a/src/lib/log/log.c
+++ b/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"
diff --git a/src/lib/log/log_sys.c b/src/lib/log/log_sys.c
new file mode 100644
index 000000000..94ec97fdc
--- /dev/null
+++ b/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,
+};
diff --git a/src/lib/log/log_sys.h b/src/lib/log/log_sys.h
new file mode 100644
index 000000000..f7afbb279
--- /dev/null
+++ b/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) */





More information about the tor-commits mailing list