subsys.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_SUBSYS_T
  6. #define TOR_SUBSYS_T
  7. #include <stdbool.h>
  8. struct dispatch_connector_t;
  9. /**
  10. * A subsystem is a part of Tor that is initialized, shut down, configured,
  11. * and connected to other parts of Tor.
  12. *
  13. * Subsystems
  14. **/
  15. typedef struct subsys_fns_t {
  16. /**
  17. * The name of this subsystem. It should be a programmer-readable
  18. * identifier.
  19. **/
  20. const char *name;
  21. /**
  22. * Whether this subsystem is supported -- that is, whether it is compiled
  23. * into Tor. For most subsystems, this should be true.
  24. **/
  25. bool supported;
  26. /**
  27. * The 'initialization level' for the subsystem. It should run from -100
  28. * through +100. The subsystems are initialized from lowest level to
  29. * highest, and shut down from highest level to lowest.
  30. **/
  31. int level;
  32. /**
  33. * Initialize any global components of this subsystem.
  34. *
  35. * This function MAY rely on any lower-level subsystem being initialized.
  36. *
  37. * This function MUST NOT rely on any runtime configuration information;
  38. * it is only for global state or pre-configuration state.
  39. *
  40. * This function MUST NOT have any parts that can fail.
  41. **/
  42. int (*initialize)(void);
  43. /**
  44. * Connect a subsystem to the message dispatch system.
  45. **/
  46. int (*add_pubsub)(struct dispatch_connector_t *);
  47. /**
  48. * Perform any necessary pre-fork cleanup. This function may not fail.
  49. */
  50. void (*prefork)(void);
  51. /**
  52. * Perform any necessary post-fork setup. This function may not fail.
  53. */
  54. void (*postfork)(void);
  55. /**
  56. * Free any thread-local resources held by this subsystem. Called before
  57. * the thread exits.
  58. */
  59. void (*thread_cleanup)(void);
  60. /**
  61. * Free all resources held by this subsystem.
  62. *
  63. * This function is not allowed to fail.
  64. **/
  65. void (*shutdown)(void);
  66. } subsys_fns_t;
  67. #define MIN_SUBSYS_LEVEL -100
  68. #define MAX_SUBSYS_LEVEL 100
  69. /* All tor "libraries" (in src/libs) should have a subsystem level equal to or
  70. * less than this value. */
  71. #define SUBSYS_LEVEL_LIBS -10
  72. #endif