[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Move monotonic time setup into a subsystem



commit 207253df8d7c040840c7f4305534e6979bfc7bf7
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Nov 2 18:09:44 2018 -0400

    Move monotonic time setup into a subsystem
---
 src/app/main/main.c           |  2 --
 src/app/main/subsystem_list.c |  2 ++
 src/lib/time/.may_include     |  1 +
 src/lib/time/include.am       |  2 ++
 src/lib/time/time_sys.c       | 26 ++++++++++++++++++++++++++
 src/lib/time/time_sys.h       | 14 ++++++++++++++
 src/test/testing_common.c     |  2 --
 7 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/app/main/main.c b/src/app/main/main.c
index 74c3c41e5..bb2e9f5cd 100644
--- a/src/app/main/main.c
+++ b/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*));
diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c
index dd6456822..a9189b994 100644
--- a/src/app/main/subsystem_list.c
+++ b/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,
 };
diff --git a/src/lib/time/.may_include b/src/lib/time/.may_include
index 2c7e37a83..40a18805a 100644
--- a/src/lib/time/.may_include
+++ b/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
 
diff --git a/src/lib/time/include.am b/src/lib/time/include.am
index a3f93a374..dae16f49a 100644
--- a/src/lib/time/include.am
+++ b/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
diff --git a/src/lib/time/time_sys.c b/src/lib/time/time_sys.c
new file mode 100644
index 000000000..2303874f2
--- /dev/null
+++ b/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,
+};
diff --git a/src/lib/time/time_sys.h b/src/lib/time/time_sys.h
new file mode 100644
index 000000000..0f1aebc26
--- /dev/null
+++ b/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) */
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 1362f2971..333dbc436 100644
--- a/src/test/testing_common.c
+++ b/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);



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