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

[tor-commits] [tor/master] Turn "compress" into a subsystem.



commit 019a044e5e6586fb42a171cb98aea15a72bd5a13
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Nov 2 18:34:56 2018 -0400

    Turn "compress" into a subsystem.
---
 src/app/main/main.c             |  2 --
 src/app/main/subsystem_list.c   |  2 ++
 src/lib/compress/.may_include   |  1 +
 src/lib/compress/compress.c     | 15 ++++++++++++++-
 src/lib/compress/compress.h     |  2 +-
 src/lib/compress/compress_sys.h | 14 ++++++++++++++
 src/lib/compress/include.am     |  1 +
 src/test/testing_common.c       |  1 -
 8 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/app/main/main.c b/src/app/main/main.c
index bb2e9f5cd..6240609ee 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -1367,8 +1367,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
 
   init_protocol_warning_severity_level();
 
-  tor_compress_init();
-
   int argc = tor_cfg->argc + tor_cfg->argc_owned;
   char **argv = tor_calloc(argc, sizeof(char*));
   memcpy(argv, tor_cfg->argv, tor_cfg->argc*sizeof(char*));
diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c
index a9189b994..e47b05da1 100644
--- a/src/app/main/subsystem_list.c
+++ b/src/app/main/subsystem_list.c
@@ -8,6 +8,7 @@
 #include "lib/cc/compat_compiler.h"
 #include "lib/cc/torint.h"
 
+#include "lib/compress/compress_sys.h"
 #include "lib/crypt_ops/crypto_sys.h"
 #include "lib/err/torerr_sys.h"
 #include "lib/log/log_sys.h"
@@ -30,6 +31,7 @@ const subsys_fns_t *tor_subsystems[] = {
   &sys_logging,
   &sys_time,
   &sys_network,
+  &sys_compress,
   &sys_crypto,
 };
 
diff --git a/src/lib/compress/.may_include b/src/lib/compress/.may_include
index 68fe9f1c5..4870259ec 100644
--- a/src/lib/compress/.may_include
+++ b/src/lib/compress/.may_include
@@ -8,5 +8,6 @@ lib/intmath/*.h
 lib/log/*.h
 lib/malloc/*.h
 lib/string/*.h
+lib/subsys/*.h
 lib/testsupport/*.h
 lib/thread/*.h
diff --git a/src/lib/compress/compress.c b/src/lib/compress/compress.c
index 2ad9b15b2..0d134fd1b 100644
--- a/src/lib/compress/compress.c
+++ b/src/lib/compress/compress.c
@@ -29,10 +29,12 @@
 #include "lib/compress/compress.h"
 #include "lib/compress/compress_lzma.h"
 #include "lib/compress/compress_none.h"
+#include "lib/compress/compress_sys.h"
 #include "lib/compress/compress_zlib.h"
 #include "lib/compress/compress_zstd.h"
 #include "lib/intmath/cmp.h"
 #include "lib/malloc/malloc.h"
+#include "lib/subsys/subsys.h"
 #include "lib/thread/threads.h"
 
 /** Total number of bytes allocated for compression state overhead. */
@@ -660,7 +662,7 @@ tor_compress_state_size(const tor_compress_state_t *state)
 }
 
 /** Initialize all compression modules. */
-void
+int
 tor_compress_init(void)
 {
   atomic_counter_init(&total_compress_allocation);
@@ -668,6 +670,8 @@ tor_compress_init(void)
   tor_zlib_init();
   tor_lzma_init();
   tor_zstd_init();
+
+  return 0;
 }
 
 /** Warn if we had any problems while setting up our compression libraries.
@@ -677,5 +681,14 @@ tor_compress_init(void)
 void
 tor_compress_log_init_warnings(void)
 {
+  // XXXX can we move this into tor_compress_init() after all?  log.c queues
+  // XXXX log messages at startup.
   tor_zstd_warn_if_version_mismatched();
 }
+
+const subsys_fns_t sys_compress = {
+  .name = "compress",
+  .supported = true,
+  .level = -70,
+  .initialize = tor_compress_init,
+};
diff --git a/src/lib/compress/compress.h b/src/lib/compress/compress.h
index 4466e27c4..4dd650623 100644
--- a/src/lib/compress/compress.h
+++ b/src/lib/compress/compress.h
@@ -89,7 +89,7 @@ void tor_compress_free_(tor_compress_state_t *state);
 
 size_t tor_compress_state_size(const tor_compress_state_t *state);
 
-void tor_compress_init(void);
+int tor_compress_init(void);
 void tor_compress_log_init_warnings(void);
 
 struct buf_t;
diff --git a/src/lib/compress/compress_sys.h b/src/lib/compress/compress_sys.h
new file mode 100644
index 000000000..a162140cf
--- /dev/null
+++ b/src/lib/compress/compress_sys.h
@@ -0,0 +1,14 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file compress_sys.h
+ * \brief Declare subsystem object for the compress module
+ **/
+
+#ifndef TOR_COMPRESS_SYS_H
+#define TOR_COMPRESS_SYS_H
+
+extern const struct subsys_fns_t sys_compress;
+
+#endif /* !defined(TOR_COMPRESS_SYS_H) */
diff --git a/src/lib/compress/include.am b/src/lib/compress/include.am
index 75c9032bd..b95277957 100644
--- a/src/lib/compress/include.am
+++ b/src/lib/compress/include.am
@@ -22,5 +22,6 @@ noinst_HEADERS	+=				\
 	src/lib/compress/compress.h		\
 	src/lib/compress/compress_lzma.h	\
 	src/lib/compress/compress_none.h	\
+	src/lib/compress/compress_sys.h		\
 	src/lib/compress/compress_zlib.h	\
 	src/lib/compress/compress_zstd.h
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 333dbc436..6d2db28f1 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -255,7 +255,6 @@ main(int c, const char **v)
   subsystems_init_upto(SUBSYS_LEVEL_LIBS);
 
   options = options_new();
-  tor_compress_init();
 
   struct tor_libevent_cfg cfg;
   memset(&cfg, 0, sizeof(cfg));



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