subsys.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2019, 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 pubsub_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. * All callbacks are optional -- if a callback is set to NULL, the subsystem
  14. * manager will treat it as a no-op.
  15. *
  16. * You should use c99 named-field initializers with this structure: we
  17. * will be adding more fields, often in the middle of the structure.
  18. **/
  19. typedef struct subsys_fns_t {
  20. /**
  21. * The name of this subsystem. It should be a programmer-readable
  22. * identifier.
  23. **/
  24. const char *name;
  25. /**
  26. * Whether this subsystem is supported -- that is, whether it is compiled
  27. * into Tor. For most subsystems, this should be true.
  28. **/
  29. bool supported;
  30. /**
  31. * The 'initialization level' for the subsystem. It should run from -100
  32. * through +100. The subsystems are initialized from lowest level to
  33. * highest, and shut down from highest level to lowest.
  34. **/
  35. int level;
  36. /**
  37. * Initialize any global components of this subsystem.
  38. *
  39. * This function MAY rely on any lower-level subsystem being initialized.
  40. *
  41. * This function MUST NOT rely on any runtime configuration information;
  42. * it is only for global state or pre-configuration state.
  43. *
  44. * (If you need to do any setup that depends on configuration, you'll need
  45. * to declare a configuration callback. (Not yet designed))
  46. *
  47. * This function MUST NOT have any parts that can fail.
  48. **/
  49. int (*initialize)(void);
  50. /**
  51. * Connect a subsystem to the message dispatch system.
  52. **/
  53. int (*add_pubsub)(struct pubsub_connector_t *);
  54. /**
  55. * Perform any necessary pre-fork cleanup. This function may not fail.
  56. */
  57. void (*prefork)(void);
  58. /**
  59. * Perform any necessary post-fork setup. This function may not fail.
  60. */
  61. void (*postfork)(void);
  62. /**
  63. * Initialize any thread-local resources held by this subsystem. Called
  64. * after the subsystem's global components are initialized.
  65. */
  66. void (*thread_init)(void);
  67. /**
  68. * Free any thread-local resources held by this subsystem. Called before
  69. * the thread exits.
  70. */
  71. void (*thread_cleanup)(void);
  72. /**
  73. * Free all resources held by this subsystem.
  74. *
  75. * This function is not allowed to fail.
  76. **/
  77. void (*shutdown)(void);
  78. } subsys_fns_t;
  79. #define MIN_SUBSYS_LEVEL -100
  80. #define MAX_SUBSYS_LEVEL 100
  81. /* All tor "libraries" (in src/libs) should have a subsystem level equal to or
  82. * less than this value. */
  83. #define SUBSYS_LEVEL_LIBS -10
  84. #endif /* !defined(TOR_SUBSYS_T) */