Merge branch 'subsystems'

This commit is contained in:
Nick Mathewson
2018-11-09 15:01:49 -05:00
72 changed files with 1013 additions and 163 deletions
+1
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
+20 -1
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,20 @@ 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();
}
static int
subsys_compress_initialize(void)
{
return tor_compress_init();
}
const subsys_fns_t sys_compress = {
.name = "compress",
.supported = true,
.level = -70,
.initialize = subsys_compress_initialize,
};
+1 -1
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;
+14
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) */
+1
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
+1
View File
@@ -12,6 +12,7 @@ lib/malloc/*.h
lib/intmath/*.h
lib/sandbox/*.h
lib/string/*.h
lib/subsys/*.h
lib/testsupport/testsupport.h
lib/thread/*.h
lib/log/*.h
+47
View File
@@ -20,6 +20,9 @@
#include "lib/crypt_ops/crypto_openssl_mgt.h"
#include "lib/crypt_ops/crypto_nss_mgt.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_sys.h"
#include "lib/subsys/subsys.h"
#include "siphash.h"
@@ -202,3 +205,47 @@ tor_is_using_nss(void)
return 0;
#endif
}
static int
subsys_crypto_initialize(void)
{
if (crypto_early_init() < 0)
return -1;
crypto_dh_init();
return 0;
}
static void
subsys_crypto_shutdown(void)
{
crypto_global_cleanup();
}
static void
subsys_crypto_prefork(void)
{
crypto_prefork();
}
static void
subsys_crypto_postfork(void)
{
crypto_postfork();
}
static void
subsys_crypto_thread_cleanup(void)
{
crypto_thread_cleanup();
}
const struct subsys_fns_t sys_crypto = {
.name = "crypto",
.supported = true,
.level = -60,
.initialize = subsys_crypto_initialize,
.shutdown = subsys_crypto_shutdown,
.prefork = subsys_crypto_prefork,
.postfork = subsys_crypto_postfork,
.thread_cleanup = subsys_crypto_thread_cleanup,
};
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file log_crypto.h
* \brief Declare subsystem object for the crypto module.
**/
#ifndef TOR_CRYPTO_SYS_H
#define TOR_CRYPTO_SYS_H
extern const struct subsys_fns_t sys_crypto;
#endif /* !defined(TOR_CRYPTO_SYS_H) */
+1
View File
@@ -66,5 +66,6 @@ noinst_HEADERS += \
src/lib/crypt_ops/crypto_rand.h \
src/lib/crypt_ops/crypto_rsa.h \
src/lib/crypt_ops/crypto_s2k.h \
src/lib/crypt_ops/crypto_sys.h \
src/lib/crypt_ops/crypto_util.h \
src/lib/crypt_ops/digestset.h
+2
View File
@@ -1,3 +1,5 @@
orconfig.h
lib/cc/*.h
lib/err/*.h
lib/subsys/*.h
lib/version/*.h
+5 -3
View File
@@ -6,8 +6,9 @@ noinst_LIBRARIES += src/lib/libtor-err-testing.a
endif
src_lib_libtor_err_a_SOURCES = \
src/lib/err/backtrace.c \
src/lib/err/torerr.c
src/lib/err/backtrace.c \
src/lib/err/torerr.c \
src/lib/err/torerr_sys.c
src_lib_libtor_err_testing_a_SOURCES = \
$(src_lib_libtor_err_a_SOURCES)
@@ -16,4 +17,5 @@ src_lib_libtor_err_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
noinst_HEADERS += \
src/lib/err/backtrace.h \
src/lib/err/torerr.h
src/lib/err/torerr.h \
src/lib/err/torerr_sys.h
+10
View File
@@ -122,6 +122,16 @@ tor_log_set_sigsafe_err_fds(const int *fds, int n)
n_sigsafe_log_fds = n;
}
/**
* Reset the list of emergency error fds to its default.
*/
void
tor_log_reset_sigsafe_err_fds(void)
{
int fds[] = { STDERR_FILENO };
tor_log_set_sigsafe_err_fds(fds, 1);
}
/**
* Set the granularity (in ms) to use when reporting fatal errors outside
* the logging system.
+1
View File
@@ -39,6 +39,7 @@ void tor_raw_assertion_failed_msg_(const char *file, int line,
void tor_log_err_sigsafe(const char *m, ...);
int tor_log_get_sigsafe_err_fds(const int **out);
void tor_log_set_sigsafe_err_fds(const int *fds, int n);
void tor_log_reset_sigsafe_err_fds(void);
void tor_log_sigsafe_err_set_granularity(int ms);
int format_hex_number_sigsafe(unsigned long x, char *buf, int max_len);
+40
View File
@@ -0,0 +1,40 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file torerr_sys.c
* \brief Subsystem object for the error handling subsystem.
**/
#include "orconfig.h"
#include "lib/err/backtrace.h"
#include "lib/err/torerr.h"
#include "lib/err/torerr_sys.h"
#include "lib/subsys/subsys.h"
#include "lib/version/torversion.h"
#include <stddef.h>
static int
subsys_torerr_initialize(void)
{
if (configure_backtrace_handler(get_version()) < 0)
return -1;
tor_log_reset_sigsafe_err_fds();
return 0;
}
static void
subsys_torerr_shutdown(void)
{
tor_log_reset_sigsafe_err_fds();
clean_up_backtrace_handler();
}
const subsys_fns_t sys_torerr = {
.name = "err",
.level = -100,
.supported = true,
.initialize = subsys_torerr_initialize,
.shutdown = subsys_torerr_shutdown
};
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file torerr_sys.h
* \brief Declare subsystem object for torerr.c
**/
#ifndef TOR_TORERR_SYS_H
#define TOR_TORERR_SYS_H
extern const struct subsys_fns_t sys_torerr;
#endif /* !defined(TOR_TORERR_SYS_H) */
+2 -2
View File
@@ -9,7 +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
micro-revision.i
+2 -8
View File
@@ -7,9 +7,9 @@ endif
src_lib_libtor_log_a_SOURCES = \
src/lib/log/escape.c \
src/lib/log/git_revision.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
@@ -21,16 +21,10 @@ src_lib_libtor_log_testing_a_SOURCES = \
src_lib_libtor_log_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_lib_libtor_log_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
# Declare that these object files depend on micro-revision.i. Without this
# rule, we could try to build them before micro-revision.i was created.
src/lib/log/git_revision.$(OBJEXT) \
src/lib/log/src_lib_libtor_log_testing_a-git_revision.$(OBJEXT): \
micro-revision.i
noinst_HEADERS += \
src/lib/log/escape.h \
src/lib/log/git_revision.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
+2 -1
View File
@@ -32,7 +32,8 @@
#define LOG_PRIVATE
#include "lib/log/log.h"
#include "lib/log/git_revision.h"
#include "lib/log/log_sys.h"
#include "lib/version/git_revision.h"
#include "lib/log/ratelim.h"
#include "lib/lock/compat_mutex.h"
#include "lib/smartlist_core/smartlist_core.h"
+35
View File
@@ -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
subsys_logging_initialize(void)
{
init_logging(0);
return 0;
}
static void
subsys_logging_shutdown(void)
{
logs_free_all();
escaped(NULL);
}
const subsys_fns_t sys_logging = {
.name = "log",
.supported = true,
.level = -90,
.initialize = subsys_logging_initialize,
.shutdown = subsys_logging_shutdown,
};
+14
View File
@@ -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) */
+1
View File
@@ -11,5 +11,6 @@ lib/lock/*.h
lib/log/*.h
lib/net/*.h
lib/string/*.h
lib/subsys/*.h
lib/testsupport/*.h
lib/malloc/*.h
+2
View File
@@ -11,6 +11,7 @@ src_lib_libtor_net_a_SOURCES = \
src/lib/net/buffers_net.c \
src/lib/net/gethostname.c \
src/lib/net/inaddr.c \
src/lib/net/network_sys.c \
src/lib/net/resolve.c \
src/lib/net/socket.c \
src/lib/net/socketpair.c
@@ -28,6 +29,7 @@ noinst_HEADERS += \
src/lib/net/inaddr.h \
src/lib/net/inaddr_st.h \
src/lib/net/nettypes.h \
src/lib/net/network_sys.h \
src/lib/net/resolve.h \
src/lib/net/socket.h \
src/lib/net/socketpair.h \
+44
View File
@@ -0,0 +1,44 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file network_sys.c
* \brief Subsystem object for networking setup.
**/
#include "orconfig.h"
#include "lib/subsys/subsys.h"
#include "lib/net/network_sys.h"
#include "lib/net/resolve.h"
#include "lib/net/socket.h"
#ifdef _WIN32
#include <winsock2.h>
#include <windows.h>
#endif
static int
subsys_network_initialize(void)
{
if (network_init() < 0)
return -1;
return 0;
}
static void
subsys_network_shutdown(void)
{
#ifdef _WIN32
WSACleanup();
#endif
tor_free_getaddrinfo_cache();
}
const subsys_fns_t sys_network = {
.name = "network",
.level = -90,
.supported = true,
.initialize = subsys_network_initialize,
.shutdown = subsys_network_shutdown,
};
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file log_network.h
* \brief Declare subsystem object for the network module.
**/
#ifndef TOR_NETWORK_SYS_H
#define TOR_NETWORK_SYS_H
extern const struct subsys_fns_t sys_network;
#endif /* !defined(TOR_NETWORK_SYS_H) */
+1
View File
@@ -11,6 +11,7 @@ lib/malloc/*.h
lib/net/*.h
lib/process/*.h
lib/string/*.h
lib/subsys/*.h
lib/testsupport/*.h
lib/thread/*.h
+4 -2
View File
@@ -12,7 +12,8 @@ src_lib_libtor_process_a_SOURCES = \
src/lib/process/restrict.c \
src/lib/process/setuid.c \
src/lib/process/subprocess.c \
src/lib/process/waitpid.c
src/lib/process/waitpid.c \
src/lib/process/winprocess_sys.c
src_lib_libtor_process_testing_a_SOURCES = \
$(src_lib_libtor_process_a_SOURCES)
@@ -26,4 +27,5 @@ noinst_HEADERS += \
src/lib/process/restrict.h \
src/lib/process/setuid.h \
src/lib/process/subprocess.h \
src/lib/process/waitpid.h
src/lib/process/waitpid.h \
src/lib/process/winprocess_sys.h
+64
View File
@@ -0,0 +1,64 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file winprocess_sys.c
* \brief Subsystem object for windows process setup.
**/
#include "orconfig.h"
#include "lib/subsys/subsys.h"
#include "lib/process/winprocess_sys.h"
#include <stdbool.h>
#include <stddef.h>
#ifdef _WIN32
#include <windows.h>
#define WINPROCESS_SYS_ENABLED true
static int
subsys_winprocess_initialize(void)
{
#ifndef HeapEnableTerminationOnCorruption
#define HeapEnableTerminationOnCorruption 1
#endif
/* On heap corruption, just give up; don't try to play along. */
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
/* SetProcessDEPPolicy is only supported on 32-bit Windows.
* (On 64-bit Windows it always fails, and some compilers don't like the
* PSETDEP cast.)
* 32-bit Windows defines _WIN32.
* 64-bit Windows defines _WIN32 and _WIN64. */
#ifndef _WIN64
/* Call SetProcessDEPPolicy to permanently enable DEP.
The function will not resolve on earlier versions of Windows,
and failure is not dangerous. */
HMODULE hMod = GetModuleHandleA("Kernel32.dll");
if (hMod) {
typedef BOOL (WINAPI *PSETDEP)(DWORD);
PSETDEP setdeppolicy = (PSETDEP)GetProcAddress(hMod,
"SetProcessDEPPolicy");
if (setdeppolicy) {
/* PROCESS_DEP_ENABLE | PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION */
setdeppolicy(3);
}
}
#endif /* !defined(_WIN64) */
return 0;
}
#else /* !defined(_WIN32) */
#define WINPROCESS_SYS_ENABLED false
#define subsys_winprocess_initialize NULL
#endif /* defined(_WIN32) */
const subsys_fns_t sys_winprocess = {
.name = "winprocess",
.level = -100,
.supported = WINPROCESS_SYS_ENABLED,
.initialize = subsys_winprocess_initialize,
};
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file winprocess_sys.h
* \brief Declare subsystem object for winprocess.c
**/
#ifndef TOR_WINPROCESS_SYS_H
#define TOR_WINPROCESS_SYS_H
extern const struct subsys_fns_t sys_winprocess;
#endif /* !defined(TOR_WINPROCESS_SYS_H) */
+1
View File
@@ -0,0 +1 @@
orconfig.h
+3
View File
@@ -0,0 +1,3 @@
noinst_HEADERS += \
src/lib/subsys/subsys.h
+95
View File
@@ -0,0 +1,95 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_SUBSYS_T
#define TOR_SUBSYS_T
#include <stdbool.h>
struct dispatch_connector_t;
/**
* A subsystem is a part of Tor that is initialized, shut down, configured,
* and connected to other parts of Tor.
*
* All callbacks are optional -- if a callback is set to NULL, the subsystem
* manager will treat it as a no-op.
*
* You should use c99 named-field initializers with this structure: we
* will be adding more fields, often in the middle of the structure.
**/
typedef struct subsys_fns_t {
/**
* The name of this subsystem. It should be a programmer-readable
* identifier.
**/
const char *name;
/**
* Whether this subsystem is supported -- that is, whether it is compiled
* into Tor. For most subsystems, this should be true.
**/
bool supported;
/**
* The 'initialization level' for the subsystem. It should run from -100
* through +100. The subsystems are initialized from lowest level to
* highest, and shut down from highest level to lowest.
**/
int level;
/**
* Initialize any global components of this subsystem.
*
* This function MAY rely on any lower-level subsystem being initialized.
*
* This function MUST NOT rely on any runtime configuration information;
* it is only for global state or pre-configuration state.
*
* (If you need to do any setup that depends on configuration, you'll need
* to declare a configuration callback. (Not yet designed))
*
* This function MUST NOT have any parts that can fail.
**/
int (*initialize)(void);
/**
* Connect a subsystem to the message dispatch system.
**/
int (*add_pubsub)(struct dispatch_connector_t *);
/**
* Perform any necessary pre-fork cleanup. This function may not fail.
*/
void (*prefork)(void);
/**
* Perform any necessary post-fork setup. This function may not fail.
*/
void (*postfork)(void);
/**
* Free any thread-local resources held by this subsystem. Called before
* the thread exits.
*/
void (*thread_cleanup)(void);
/**
* Free all resources held by this subsystem.
*
* This function is not allowed to fail.
**/
void (*shutdown)(void);
} subsys_fns_t;
#define MIN_SUBSYS_LEVEL -100
#define MAX_SUBSYS_LEVEL 100
/* All tor "libraries" (in src/libs) should have a subsystem level equal to or
* less than this value. */
#define SUBSYS_LEVEL_LIBS -10
#endif
+1
View File
@@ -2,6 +2,7 @@ orconfig.h
lib/cc/*.h
lib/lock/*.h
lib/log/*.h
lib/subsys/*.h
lib/testsupport/*.h
lib/thread/*.h
lib/wallclock/*.h
+16
View File
@@ -14,9 +14,11 @@
#include "orconfig.h"
#include <stdlib.h>
#include "lib/thread/threads.h"
#include "lib/thread/thread_sys.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/subsys/subsys.h"
#include <string.h>
@@ -109,3 +111,17 @@ atomic_counter_exchange(atomic_counter_t *counter, size_t newval)
return oldval;
}
#endif /* !defined(HAVE_WORKING_STDATOMIC) */
static int
subsys_threads_initialize(void)
{
tor_threads_init();
return 0;
}
const subsys_fns_t sys_threads = {
.name = "threads",
.supported = true,
.level = -95,
.initialize = subsys_threads_initialize,
};
+3 -2
View File
@@ -23,5 +23,6 @@ src_lib_libtor_thread_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_lib_libtor_thread_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
noinst_HEADERS += \
src/lib/thread/threads.h \
src/lib/thread/numcpus.h
src/lib/thread/numcpus.h \
src/lib/thread/thread_sys.h \
src/lib/thread/threads.h
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file threads_sys.h
* \brief Declare subsystem object for threads library
**/
#ifndef TOR_THREADS_SYS_H
#define TOR_THREADS_SYS_H
extern const struct subsys_fns_t sys_threads;
#endif /* !defined(TOR_THREADS_SYS_H) */
+1
View File
@@ -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
View File
@@ -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
View File
@@ -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
subsys_time_initialize(void)
{
monotime_init();
return 0;
}
const subsys_fns_t sys_time = {
.name = "time",
.level = -90,
.supported = true,
.initialize = subsys_time_initialize,
};
+14
View File
@@ -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) */
+1
View File
@@ -11,6 +11,7 @@ lib/log/*.h
lib/malloc/*.h
lib/net/*.h
lib/string/*.h
lib/subsys/*.h
lib/testsupport/testsupport.h
lib/tls/*.h
+1
View File
@@ -36,5 +36,6 @@ noinst_HEADERS += \
src/lib/tls/tortls.h \
src/lib/tls/tortls_internal.h \
src/lib/tls/tortls_st.h \
src/lib/tls/tortls_sys.h \
src/lib/tls/x509.h \
src/lib/tls/x509_internal.h
+14
View File
@@ -7,6 +7,7 @@
#define TOR_X509_PRIVATE
#include "lib/tls/x509.h"
#include "lib/tls/x509_internal.h"
#include "lib/tls/tortls_sys.h"
#include "lib/tls/tortls.h"
#include "lib/tls/tortls_st.h"
#include "lib/tls/tortls_internal.h"
@@ -15,6 +16,7 @@
#include "lib/crypt_ops/crypto_rsa.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/net/socket.h"
#include "lib/subsys/subsys.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -440,3 +442,15 @@ tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_t **identity)
return rv;
}
static void
subsys_tortls_shutdown(void)
{
tor_tls_free_all();
}
const subsys_fns_t sys_tortls = {
.name = "tortls",
.level = -50,
.shutdown = subsys_tortls_shutdown
};
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file tortls_sys.h
* \brief Declare subsystem object for the tortls module
**/
#ifndef TOR_TORTLS_SYS_H
#define TOR_TORTLS_SYS_H
extern const struct subsys_fns_t sys_tortls;
#endif /* !defined(TOR_TORTLS_SYS_H) */
+3
View File
@@ -0,0 +1,3 @@
orconfig.h
micro-revision.i
lib/version/*.h
@@ -4,7 +4,7 @@
/* See LICENSE for licensing information */
#include "orconfig.h"
#include "lib/log/git_revision.h"
#include "lib/version/git_revision.h"
/** String describing which Tor Git repository version the source was
* built from. This string is generated by a bit of shell kludging in
+25
View File
@@ -0,0 +1,25 @@
noinst_LIBRARIES += src/lib/libtor-version.a
if UNITTESTS_ENABLED
noinst_LIBRARIES += src/lib/libtor-version-testing.a
endif
src_lib_libtor_version_a_SOURCES = \
src/lib/version/git_revision.c \
src/lib/version/version.c
src_lib_libtor_version_testing_a_SOURCES = \
$(src_lib_libtor_version_a_SOURCES)
src_lib_libtor_version_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_lib_libtor_version_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
# Declare that these object files depend on micro-revision.i. Without this
# rule, we could try to build them before micro-revision.i was created.
src/lib/version/git_revision.$(OBJEXT) \
src/lib/version/src_lib_libtor_version_testing_a-git_revision.$(OBJEXT): \
micro-revision.i
noinst_HEADERS += \
src/lib/version/git_revision.h \
src/lib/version/torversion.h
+12
View File
@@ -0,0 +1,12 @@
/* Copyright 2001-2004 Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_VERSION_H
#define TOR_VERSION_H
const char *get_version(void);
const char *get_short_version(void);
#endif /* !defined(TOR_VERSION_H) */
+50
View File
@@ -0,0 +1,50 @@
/* Copyright 2001-2004 Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#include "orconfig.h"
#include "lib/version/torversion.h"
#include "lib/version/git_revision.h"
#include <stdio.h>
#include <string.h>
/** A shorter version of this Tor process's version, for export in our router
* descriptor. (Does not include the git version, if any.) */
static const char the_short_tor_version[] =
VERSION
#ifdef TOR_BUILD_TAG
" ("TOR_BUILD_TAG")"
#endif
"";
#define MAX_VERSION_LEN 128
/** The version of this Tor process, possibly including git version */
static char the_tor_version[MAX_VERSION_LEN] = "";
/** Return the current Tor version. */
const char *
get_version(void)
{
if (the_tor_version[0] == 0) {
if (strlen(tor_git_revision)) {
snprintf(the_tor_version, sizeof(the_tor_version),
"%s (git-%s)", the_short_tor_version, tor_git_revision);
} else {
snprintf(the_tor_version, sizeof(the_tor_version),
"%s", the_short_tor_version);
}
the_tor_version[sizeof(the_tor_version)-1] = 0;
}
return the_tor_version;
}
/** Return the current Tor version, without any git tag. */
const char *
get_short_version(void)
{
return the_short_tor_version;
}
+1
View File
@@ -3,4 +3,5 @@ lib/cc/*.h
lib/err/*.h
lib/wallclock/*.h
lib/string/*.h
lib/subsys/*.h
lib/testsupport/*.h
+16
View File
@@ -9,7 +9,9 @@
**/
#include "orconfig.h"
#include "lib/subsys/subsys.h"
#include "lib/wallclock/approx_time.h"
#include "lib/wallclock/wallclock_sys.h"
/* =====
* Cached time
@@ -41,3 +43,17 @@ update_approx_time(time_t now)
cached_approx_time = now;
}
#endif /* !defined(TIME_IS_FAST) */
static int
subsys_wallclock_initialize(void)
{
update_approx_time(time(NULL));
return 0;
}
const subsys_fns_t sys_wallclock = {
.name = "wallclock",
.supported = true,
.level = -99,
.initialize = subsys_wallclock_initialize,
};
+2 -1
View File
@@ -19,4 +19,5 @@ noinst_HEADERS += \
src/lib/wallclock/approx_time.h \
src/lib/wallclock/timeval.h \
src/lib/wallclock/time_to_tm.h \
src/lib/wallclock/tor_gettimeofday.h
src/lib/wallclock/tor_gettimeofday.h \
src/lib/wallclock/wallclock_sys.h
+14
View File
@@ -0,0 +1,14 @@
/* Copyright (c) 2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file wallclock_sys.h
* \brief Declare subsystem object for the wallclock module.
**/
#ifndef TOR_WALLCLOCK_SYS_H
#define TOR_WALLCLOCK_SYS_H
extern const struct subsys_fns_t sys_wallclock;
#endif /* !defined(TOR_WALLCLOCK_SYS_H) */