torerr_sys.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (c) 2018-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file torerr_sys.c
  5. * \brief Subsystem object for the error handling subsystem.
  6. **/
  7. #include "orconfig.h"
  8. #include "lib/err/backtrace.h"
  9. #include "lib/err/torerr.h"
  10. #include "lib/err/torerr_sys.h"
  11. #include "lib/subsys/subsys.h"
  12. #include "lib/version/torversion.h"
  13. #include <stddef.h>
  14. static int
  15. subsys_torerr_initialize(void)
  16. {
  17. if (configure_backtrace_handler(get_version()) < 0)
  18. return -1;
  19. tor_log_reset_sigsafe_err_fds();
  20. return 0;
  21. }
  22. static void
  23. subsys_torerr_shutdown(void)
  24. {
  25. /* Stop handling signals with backtraces, then close the logs. */
  26. clean_up_backtrace_handler();
  27. /* We can't log any log messages after this point: we've closed all the log
  28. * fds, including stdio. */
  29. tor_log_close_sigsafe_err_fds();
  30. }
  31. const subsys_fns_t sys_torerr = {
  32. .name = "err",
  33. /* Low-level error handling is a diagnostic feature, we want it to init
  34. * right after windows process security, and shutdown last.
  35. * (Security never shuts down.) */
  36. .level = -99,
  37. .supported = true,
  38. .initialize = subsys_torerr_initialize,
  39. .shutdown = subsys_torerr_shutdown
  40. };