mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +01:00
Make initialization for the "err" library into a subsystem.
This commit is contained in:
parent
6e7ff8cba0
commit
175153a329
@ -69,7 +69,6 @@
|
|||||||
#include "lib/container/buffers.h"
|
#include "lib/container/buffers.h"
|
||||||
#include "lib/crypt_ops/crypto_rand.h"
|
#include "lib/crypt_ops/crypto_rand.h"
|
||||||
#include "lib/crypt_ops/crypto_s2k.h"
|
#include "lib/crypt_ops/crypto_s2k.h"
|
||||||
#include "lib/err/backtrace.h"
|
|
||||||
#include "lib/geoip/geoip.h"
|
#include "lib/geoip/geoip.h"
|
||||||
|
|
||||||
#include "lib/process/waitpid.h"
|
#include "lib/process/waitpid.h"
|
||||||
@ -822,7 +821,6 @@ tor_free_all(int postfork)
|
|||||||
if (!postfork) {
|
if (!postfork) {
|
||||||
escaped(NULL);
|
escaped(NULL);
|
||||||
esc_router_info(NULL);
|
esc_router_info(NULL);
|
||||||
clean_up_backtrace_handler();
|
|
||||||
logs_free_all(); /* free log strings. do this last so logs keep working. */
|
logs_free_all(); /* free log strings. do this last so logs keep working. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1419,14 +1417,6 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
|
|||||||
#endif /* !defined(_WIN64) */
|
#endif /* !defined(_WIN64) */
|
||||||
#endif /* defined(_WIN32) */
|
#endif /* defined(_WIN32) */
|
||||||
|
|
||||||
{
|
|
||||||
int bt_err = configure_backtrace_handler(get_version());
|
|
||||||
if (bt_err < 0) {
|
|
||||||
log_warn(LD_BUG, "Unable to install backtrace handler: %s",
|
|
||||||
strerror(-bt_err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
|
#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
|
||||||
event_set_mem_functions(tor_malloc_, tor_realloc_, tor_free_);
|
event_set_mem_functions(tor_malloc_, tor_realloc_, tor_free_);
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,13 +8,15 @@
|
|||||||
#include "lib/cc/compat_compiler.h"
|
#include "lib/cc/compat_compiler.h"
|
||||||
#include "lib/cc/torint.h"
|
#include "lib/cc/torint.h"
|
||||||
|
|
||||||
|
#include "lib/err/torerr_sys.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global list of the subsystems in Tor, in the order of their initialization.
|
* Global list of the subsystems in Tor, in the order of their initialization.
|
||||||
**/
|
**/
|
||||||
const subsys_fns_t *tor_subsystems[] = {
|
const subsys_fns_t *tor_subsystems[] = {
|
||||||
NULL // placeholder.
|
&sys_torerr,
|
||||||
};
|
};
|
||||||
|
|
||||||
const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems);
|
const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
orconfig.h
|
orconfig.h
|
||||||
lib/cc/*.h
|
lib/cc/*.h
|
||||||
lib/err/*.h
|
lib/err/*.h
|
||||||
|
lib/subsys/*.h
|
||||||
|
lib/version/*.h
|
@ -7,7 +7,8 @@ endif
|
|||||||
|
|
||||||
src_lib_libtor_err_a_SOURCES = \
|
src_lib_libtor_err_a_SOURCES = \
|
||||||
src/lib/err/backtrace.c \
|
src/lib/err/backtrace.c \
|
||||||
src/lib/err/torerr.c
|
src/lib/err/torerr.c \
|
||||||
|
src/lib/err/torerr_sys.c
|
||||||
|
|
||||||
src_lib_libtor_err_testing_a_SOURCES = \
|
src_lib_libtor_err_testing_a_SOURCES = \
|
||||||
$(src_lib_libtor_err_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 += \
|
noinst_HEADERS += \
|
||||||
src/lib/err/backtrace.h \
|
src/lib/err/backtrace.h \
|
||||||
src/lib/err/torerr.h
|
src/lib/err/torerr.h \
|
||||||
|
src/lib/err/torerr_sys.h
|
||||||
|
@ -122,6 +122,16 @@ tor_log_set_sigsafe_err_fds(const int *fds, int n)
|
|||||||
n_sigsafe_log_fds = 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
|
* Set the granularity (in ms) to use when reporting fatal errors outside
|
||||||
* the logging system.
|
* the logging system.
|
||||||
|
@ -39,6 +39,7 @@ void tor_raw_assertion_failed_msg_(const char *file, int line,
|
|||||||
void tor_log_err_sigsafe(const char *m, ...);
|
void tor_log_err_sigsafe(const char *m, ...);
|
||||||
int tor_log_get_sigsafe_err_fds(const int **out);
|
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_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);
|
void tor_log_sigsafe_err_set_granularity(int ms);
|
||||||
|
|
||||||
int format_hex_number_sigsafe(unsigned long x, char *buf, int max_len);
|
int format_hex_number_sigsafe(unsigned long x, char *buf, int max_len);
|
||||||
|
39
src/lib/err/torerr_sys.c
Normal file
39
src/lib/err/torerr_sys.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* 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
|
||||||
|
torerr_subsys_init(void)
|
||||||
|
{
|
||||||
|
configure_backtrace_handler(get_version());
|
||||||
|
tor_log_reset_sigsafe_err_fds();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static void
|
||||||
|
torerr_subsys_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 = torerr_subsys_init,
|
||||||
|
.shutdown = torerr_subsys_shutdown
|
||||||
|
};
|
14
src/lib/err/torerr_sys.h
Normal file
14
src/lib/err/torerr_sys.h
Normal 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) */
|
Loading…
Reference in New Issue
Block a user