Browse Source

Move monotonic time setup into a subsystem

Nick Mathewson 5 years ago
parent
commit
207253df8d

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

@@ -1248,7 +1248,6 @@ static int
 run_tor_main_loop(void)
 {
   handle_signals();
-  monotime_init();
   timers_initialize();
   initialize_mainloop_events();
 
@@ -1369,7 +1368,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
   init_protocol_warning_severity_level();
 
   tor_compress_init();
-  monotime_init();
 
   int argc = tor_cfg->argc + tor_cfg->argc_owned;
   char **argv = tor_calloc(argc, sizeof(char*));

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

@@ -14,6 +14,7 @@
 #include "lib/net/network_sys.h"
 #include "lib/process/winprocess_sys.h"
 #include "lib/thread/thread_sys.h"
+#include "lib/time/time_sys.h"
 #include "lib/wallclock/wallclock_sys.h"
 
 #include <stddef.h>
@@ -27,6 +28,7 @@ const subsys_fns_t *tor_subsystems[] = {
   &sys_wallclock,
   &sys_threads,
   &sys_logging,
+  &sys_time,
   &sys_network,
   &sys_crypto,
 };

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

@@ -4,6 +4,7 @@ lib/cc/*.h
 lib/err/*.h
 lib/intmath/*.h
 lib/log/*.h
+lib/subsys/*.h
 lib/time/*.h
 lib/wallclock/*.h
 

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

@@ -7,6 +7,7 @@ endif
 
 src_lib_libtor_time_a_SOURCES =	\
 		src/lib/time/compat_time.c	\
+		src/lib/time/time_sys.c		\
 		src/lib/time/tvdiff.c
 
 src_lib_libtor_time_testing_a_SOURCES = \
@@ -16,4 +17,5 @@ src_lib_libtor_time_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
 
 noinst_HEADERS +=				\
 		src/lib/time/compat_time.h	\
+		src/lib/time/time_sys.h		\
 		src/lib/time/tvdiff.h

+ 26 - 0
src/lib/time/time_sys.c

@@ -0,0 +1,26 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file time_sys.c
+ * \brief Subsystem object for monotime setup.
+ **/
+
+#include "orconfig.h"
+#include "lib/subsys/subsys.h"
+#include "lib/time/time_sys.h"
+#include "lib/time/compat_time.h"
+
+static int
+init_time_sys(void)
+{
+  monotime_init();
+  return 0;
+}
+
+const subsys_fns_t sys_time = {
+  .name = "time",
+  .level = -90,
+  .supported = true,
+  .initialize = init_time_sys,
+};

+ 14 - 0
src/lib/time/time_sys.h

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

+ 0 - 2
src/test/testing_common.c

@@ -257,8 +257,6 @@ main(int c, const char **v)
   options = options_new();
   tor_compress_init();
 
-  monotime_init();
-
   struct tor_libevent_cfg cfg;
   memset(&cfg, 0, sizeof(cfg));
   tor_libevent_initialize(&cfg);