evloop_sys.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * @file evloop_sys.c
  8. * @brief Subsystem definition for the event loop module
  9. **/
  10. #include "orconfig.h"
  11. #include "lib/subsys/subsys.h"
  12. #include "lib/evloop/compat_libevent.h"
  13. #include "lib/evloop/evloop_sys.h"
  14. #include "lib/log/log.h"
  15. static int
  16. subsys_evloop_initialize(void)
  17. {
  18. tor_evloop_init_threadlocals();
  19. if (tor_init_libevent_rng() < 0) {
  20. log_warn(LD_NET, "Problem initializing libevent RNG.");
  21. return -1;
  22. }
  23. return 0;
  24. }
  25. static void
  26. subsys_evloop_postfork(void)
  27. {
  28. #ifdef TOR_UNIT_TESTS
  29. tor_libevent_postfork();
  30. #endif
  31. }
  32. static void
  33. subsys_evloop_shutdown(void)
  34. {
  35. tor_libevent_free_all();
  36. tor_evloop_destroy_threadlocals();
  37. }
  38. const struct subsys_fns_t sys_evloop = {
  39. .name = "evloop",
  40. .supported = true,
  41. .level = -20,
  42. .initialize = subsys_evloop_initialize,
  43. .shutdown = subsys_evloop_shutdown,
  44. .postfork = subsys_evloop_postfork,
  45. };