diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app/main/main.c | 4 | ||||
-rw-r--r-- | src/lib/trace/include.am | 4 | ||||
-rw-r--r-- | src/lib/trace/trace.h | 21 | ||||
-rw-r--r-- | src/lib/trace/trace_stub.c | 19 | ||||
-rw-r--r-- | src/lib/trace/trace_sys.c | 5 | ||||
-rw-r--r-- | src/lib/trace/trace_sys.h | 8 |
6 files changed, 60 insertions, 1 deletions
diff --git a/src/app/main/main.c b/src/app/main/main.c index 89ba787422..e1d5772e3d 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -59,6 +59,7 @@ #include "lib/crypt_ops/crypto_rand.h" #include "lib/crypt_ops/crypto_s2k.h" #include "lib/net/resolve.h" +#include "lib/trace/trace.h" #include "lib/process/waitpid.h" #include "lib/pubsub/pubsub_build.h" @@ -602,6 +603,9 @@ tor_init(int argc, char *argv[]) rust_log_welcome_string(); #endif /* defined(HAVE_RUST) */ + /* Warn _if_ the tracing subsystem is built in. */ + tracing_log_warning(); + int init_rv = options_init_from_torrc(argc,argv); if (init_rv < 0) { log_err(LD_CONFIG,"Reading config failed--see warnings above."); diff --git a/src/lib/trace/include.am b/src/lib/trace/include.am index 8440331325..6fe1365652 100644 --- a/src/lib/trace/include.am +++ b/src/lib/trace/include.am @@ -26,6 +26,10 @@ if USE_TRACING_INSTRUMENTATION_LTTNG include src/lib/trace/lttng/include.am endif +if USE_TRACING src_lib_libtor_trace_a_SOURCES = $(LIBTOR_TRACE_A_SOURCES) +else +src_lib_libtor_trace_a_SOURCES = src/lib/trace/trace_stub.c +endif noinst_HEADERS+= $(TRACEHEADERS) diff --git a/src/lib/trace/trace.h b/src/lib/trace/trace.h index 94cbbc1e48..22589dbe94 100644 --- a/src/lib/trace/trace.h +++ b/src/lib/trace/trace.h @@ -9,7 +9,28 @@ #ifndef TOR_LIB_TRACE_TRACE_H #define TOR_LIB_TRACE_TRACE_H +#include "orconfig.h" + void tor_trace_init(void); void tor_trace_free_all(void); +#ifdef HAVE_TRACING + +#include "lib/log/log.h" + +static inline void +tracing_log_warning(void) +{ + log_warn(LD_GENERAL, + "Tracing capabilities have been built in. If this is NOT on " + "purpose, your tor is NOT safe to run."); +} + +#else + +/* NOP it. */ +#define tracing_log_warning() + +#endif /* defined(HAVE_TRACING) */ + #endif /* !defined(TOR_LIB_TRACE_TRACE_H) */ diff --git a/src/lib/trace/trace_stub.c b/src/lib/trace/trace_stub.c new file mode 100644 index 0000000000..9043efe360 --- /dev/null +++ b/src/lib/trace/trace_stub.c @@ -0,0 +1,19 @@ +/* Copyright (c) 2020, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file trace_stub.c + * \brief Stub declaratinos for use when trace library is disabled. + **/ + +#include "lib/subsys/subsys.h" + +#include "lib/trace/trace_sys.h" + +const subsys_fns_t sys_tracing = { + SUBSYS_DECLARE_LOCATION(), + + .name = "tracing", + .supported = false, + .level = TRACE_SUBSYS_LEVEL, +}; diff --git a/src/lib/trace/trace_sys.c b/src/lib/trace/trace_sys.c index d6e59f4c3d..2ba0258407 100644 --- a/src/lib/trace/trace_sys.c +++ b/src/lib/trace/trace_sys.c @@ -25,9 +25,12 @@ subsys_tracing_shutdown(void) } const subsys_fns_t sys_tracing = { + SUBSYS_DECLARE_LOCATION(), + .name = "tracing", .supported = true, - .level = -85, + .level = TRACE_SUBSYS_LEVEL, + .initialize = subsys_tracing_initialize, .shutdown = subsys_tracing_shutdown, }; diff --git a/src/lib/trace/trace_sys.h b/src/lib/trace/trace_sys.h index e9c97c08fb..d4da5a9701 100644 --- a/src/lib/trace/trace_sys.h +++ b/src/lib/trace/trace_sys.h @@ -11,4 +11,12 @@ extern const struct subsys_fns_t sys_tracing; +/** + * Subsystem level for the tracing system. + * + * Defined here so that it can be shared between the real and stub + * definitions. + **/ +#define TRACE_SUBSYS_LEVEL (-85) + #endif /* !defined(TOR_TRACE_SYS_H) */ |