evloop_sys.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if (tor_init_libevent_rng() < 0) {
  19. log_warn(LD_NET, "Problem initializing libevent RNG.");
  20. return -1;
  21. }
  22. return 0;
  23. }
  24. static void
  25. subsys_evloop_postfork(void)
  26. {
  27. #ifdef TOR_UNIT_TESTS
  28. tor_libevent_postfork();
  29. #endif
  30. }
  31. static void
  32. subsys_evloop_shutdown(void)
  33. {
  34. tor_libevent_free_all();
  35. }
  36. const struct subsys_fns_t sys_evloop = {
  37. .name = "evloop",
  38. .supported = true,
  39. .level = -20,
  40. .initialize = subsys_evloop_initialize,
  41. .shutdown = subsys_evloop_shutdown,
  42. .postfork = subsys_evloop_postfork,
  43. };