aboutsummaryrefslogtreecommitdiff
path: root/src/lib/err/torerr_sys.c
blob: a14c46f945b32391d0cdf2145827866fdb241b8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Copyright (c) 2018-2019, 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)
{
  /* Stop handling signals with backtraces, then close the logs. */
  clean_up_backtrace_handler();
  /* We can't log any log messages after this point: we've closed all the log
   * fds, including stdio. */
  tor_log_close_sigsafe_err_fds();
}

const subsys_fns_t sys_torerr = {
  .name = "err",
  .level = -100,
  .supported = true,
  .initialize = subsys_torerr_initialize,
  .shutdown = subsys_torerr_shutdown
};