[dm-devel] [PATCH v2 17/29] multipathd: add cleanup_child() exit handler
mwilck at suse.com
mwilck at suse.com
Fri Oct 16 10:44:49 UTC 2020
From: Martin Wilck <mwilck at suse.com>
cleanup_child() calls all cleanups in the right order, in an
exit handler.
Reviewed-by: Benjamin Marzinski <bmarzins at redhat.com>
Signed-off-by: Martin Wilck <mwilck at suse.com>
---
multipathd/main.c | 47 +++++++++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git a/multipathd/main.c b/multipathd/main.c
index 45fc3f0..0578445 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -3023,6 +3023,27 @@ static void cleanup_rcu(int dummy __attribute__((unused)), void *arg)
rcu_unregister_thread();
}
+static void cleanup_child(void)
+{
+ cleanup_threads();
+ cleanup_vecs();
+ cleanup_foreign();
+ cleanup_checkers();
+ cleanup_prio();
+ if (poll_dmevents)
+ cleanup_dmevent_waiter();
+
+ cleanup_pidfile();
+ if (logsink == 1)
+ log_thread_stop();
+
+ cleanup_conf();
+
+#ifdef _DEBUG_
+ dbg_free_final(NULL);
+#endif
+}
+
static int sd_notify_exit(int err)
{
#ifdef USE_SYSTEMD
@@ -3049,7 +3070,11 @@ child (__attribute__((unused)) void *param)
mlockall(MCL_CURRENT | MCL_FUTURE);
signal_init();
crdp = setup_rcu();
- on_exit(cleanup_rcu, crdp);
+
+ if (on_exit(cleanup_rcu, crdp) ||
+ atexit(cleanup_child)) {
+ fprintf(stderr, "failed to register cleanup handlers\n");
+ }
setup_thread_attr(&misc_attr, 64 * 1024, 0);
setup_thread_attr(&uevent_attr, DEFAULT_UEVENT_STACKSIZE * 1024, 0);
@@ -3063,8 +3088,6 @@ child (__attribute__((unused)) void *param)
pid_fd = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
if (pid_fd < 0) {
condlog(1, "failed to create pidfile");
- if (logsink == 1)
- log_thread_stop();
exit(1);
}
@@ -3212,24 +3235,8 @@ child (__attribute__((unused)) void *param)
exit_code = 0;
failed:
- cleanup_threads();
- cleanup_vecs();
- cleanup_foreign();
- cleanup_checkers();
- cleanup_prio();
- if (poll_dmevents)
- cleanup_dmevent_waiter();
-
- /* We're done here */
- cleanup_pidfile();
condlog(2, "--------shut down-------");
-
- if (logsink == 1)
- log_thread_stop();
- cleanup_conf();
-#ifdef _DEBUG_
- dbg_free_final(NULL);
-#endif
+ /* All cleanup is done in the cleanup_child() exit handler */
return sd_notify_exit(exit_code);
}
--
2.28.0
More information about the dm-devel
mailing list