Turn "compress" into a subsystem.

This commit is contained in:
Nick Mathewson 2018-11-02 18:34:56 -04:00
parent 207253df8d
commit 019a044e5e
8 changed files with 33 additions and 5 deletions

View File

@ -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*));

View File

@ -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,
};

View File

@ -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

View File

@ -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,
};

View File

@ -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;

View File

@ -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) */

View File

@ -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

View File

@ -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));