summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-11-01 12:40:55 -0400
committerNick Mathewson <nickm@torproject.org>2018-11-05 09:22:02 -0500
commit175153a3290b3987faacac9d5390e87e1ad4a457 (patch)
treeffe76b1752c481a4e0b47aeb2c21adb58d38a179
parent6e7ff8cba0efaf803e3ef5b5aba4123633fe0658 (diff)
downloadtor-175153a3290b3987faacac9d5390e87e1ad4a457.tar.gz
tor-175153a3290b3987faacac9d5390e87e1ad4a457.zip
Make initialization for the "err" library into a subsystem.
-rw-r--r--src/app/main/main.c10
-rw-r--r--src/app/main/subsystem_list.c4
-rw-r--r--src/lib/err/.may_include2
-rw-r--r--src/lib/err/include.am8
-rw-r--r--src/lib/err/torerr.c10
-rw-r--r--src/lib/err/torerr.h1
-rw-r--r--src/lib/err/torerr_sys.c39
-rw-r--r--src/lib/err/torerr_sys.h14
8 files changed, 74 insertions, 14 deletions
diff --git a/src/app/main/main.c b/src/app/main/main.c
index 031f570097..e3d7610c82 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -69,7 +69,6 @@
#include "lib/container/buffers.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_s2k.h"
-#include "lib/err/backtrace.h"
#include "lib/geoip/geoip.h"
#include "lib/process/waitpid.h"
@@ -822,7 +821,6 @@ tor_free_all(int postfork)
if (!postfork) {
escaped(NULL);
esc_router_info(NULL);
- clean_up_backtrace_handler();
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(_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
event_set_mem_functions(tor_malloc_, tor_realloc_, tor_free_);
#endif
diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c
index fc1249e1c6..244dbadbd9 100644
--- a/src/app/main/subsystem_list.c
+++ b/src/app/main/subsystem_list.c
@@ -8,13 +8,15 @@
#include "lib/cc/compat_compiler.h"
#include "lib/cc/torint.h"
+#include "lib/err/torerr_sys.h"
+
#include <stddef.h>
/**
* Global list of the subsystems in Tor, in the order of their initialization.
**/
const subsys_fns_t *tor_subsystems[] = {
- NULL // placeholder.
+ &sys_torerr,
};
const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems);
diff --git a/src/lib/err/.may_include b/src/lib/err/.may_include
index 48cc0ef088..daa1b6e4ca 100644
--- a/src/lib/err/.may_include
+++ b/src/lib/err/.may_include
@@ -1,3 +1,5 @@
orconfig.h
lib/cc/*.h
lib/err/*.h
+lib/subsys/*.h
+lib/version/*.h \ No newline at end of file
diff --git a/src/lib/err/include.am b/src/lib/err/include.am
index f2a409c51e..43adcd2694 100644
--- a/src/lib/err/include.am
+++ b/src/lib/err/include.am
@@ -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
diff --git a/src/lib/err/torerr.c b/src/lib/err/torerr.c
index f9e139f967..e9de86837f 100644
--- a/src/lib/err/torerr.c
+++ b/src/lib/err/torerr.c
@@ -123,6 +123,16 @@ tor_log_set_sigsafe_err_fds(const int *fds, int 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.
*/
diff --git a/src/lib/err/torerr.h b/src/lib/err/torerr.h
index d4bba6916f..b415ef73ef 100644
--- a/src/lib/err/torerr.h
+++ b/src/lib/err/torerr.h
@@ -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);
diff --git a/src/lib/err/torerr_sys.c b/src/lib/err/torerr_sys.c
new file mode 100644
index 0000000000..54666f4106
--- /dev/null
+++ b/src/lib/err/torerr_sys.c
@@ -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
+};
diff --git a/src/lib/err/torerr_sys.h b/src/lib/err/torerr_sys.h
new file mode 100644
index 0000000000..b56270d538
--- /dev/null
+++ b/src/lib/err/torerr_sys.h
@@ -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) */