aboutsummaryrefslogtreecommitdiff
path: root/src/app/main/subsysmgr.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-11-02 18:00:56 -0400
committerNick Mathewson <nickm@torproject.org>2018-11-05 09:22:02 -0500
commitcad61f0f6de48c6eab6e811a081f154b03de57b8 (patch)
tree9a3e3cb610f7a0315e5f3c56795176eba9ed1065 /src/app/main/subsysmgr.c
parent50436ccea4bd200e45196ccce7acff28f293a4de (diff)
downloadtor-cad61f0f6de48c6eab6e811a081f154b03de57b8.tar.gz
tor-cad61f0f6de48c6eab6e811a081f154b03de57b8.zip
Move prefork, postfork, and thread-exit hooks into subsys
So far, crypto is the only module that uses them, but others are likely to do so in the future.
Diffstat (limited to 'src/app/main/subsysmgr.c')
-rw-r--r--src/app/main/subsysmgr.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/app/main/subsysmgr.c b/src/app/main/subsysmgr.c
index 7974f2d238..05803ee946 100644
--- a/src/app/main/subsysmgr.c
+++ b/src/app/main/subsysmgr.c
@@ -128,3 +128,60 @@ subsystems_shutdown_downto(int target_level)
sys_initialized[i] = false;
}
}
+
+/**
+ * Run pre-fork code on all subsystems that declare any
+ **/
+void
+subsystems_prefork(void)
+{
+ check_and_setup();
+
+ for (int i = (int)n_tor_subsystems - 1; i >= 0; --i) {
+ const subsys_fns_t *sys = tor_subsystems[i];
+ if (!sys->supported)
+ continue;
+ if (! sys_initialized[i])
+ continue;
+ if (sys->prefork)
+ sys->prefork();
+ }
+}
+
+/**
+ * Run post-fork code on all subsystems that declare any
+ **/
+void
+subsystems_postfork(void)
+{
+ check_and_setup();
+
+ for (unsigned i = 0; i < n_tor_subsystems; ++i) {
+ const subsys_fns_t *sys = tor_subsystems[i];
+ if (!sys->supported)
+ continue;
+ if (! sys_initialized[i])
+ continue;
+ if (sys->postfork)
+ sys->postfork();
+ }
+}
+
+/**
+ * Run thread-clanup code on all subsystems that declare any
+ **/
+void
+subsystems_thread_cleanup(void)
+{
+ check_and_setup();
+
+ for (int i = (int)n_tor_subsystems - 1; i >= 0; --i) {
+ const subsys_fns_t *sys = tor_subsystems[i];
+ if (!sys->supported)
+ continue;
+ if (! sys_initialized[i])
+ continue;
+ if (sys->thread_cleanup)
+ sys->thread_cleanup();
+ }
+}