commit 892814e353bbf95c8183da9202f087daa74fbc12
parent fc5fc4f4abb03f869af686002623b346cd39812d
Author: Joris Vink <joris@coders.se>
Date: Tue, 23 Oct 2018 21:46:34 +0200
Add kore_[parent|worker]_teardown().
If exists these functions are called when the worker is exiting
and when right before the parent exists.
Allows for cleanup code for applications if need to do cleanup on exit.
Diffstat:
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/include/kore/kore.h b/include/kore/kore.h
@@ -808,6 +808,8 @@ void kore_buf_replace_string(struct kore_buf *,
void kore_keymgr_run(void);
void kore_keymgr_cleanup(int);
+void kore_worker_teardown(void);
+void kore_parent_teardown(void);
void kore_worker_configure(void);
void kore_parent_daemonized(void);
void kore_parent_configure(int, char **);
diff --git a/src/kore.c b/src/kore.c
@@ -119,9 +119,7 @@ version(void)
int
main(int argc, char *argv[])
{
-#if defined(KORE_SINGLE_BINARY)
struct kore_runtime_call *rcall;
-#endif
int ch, flags;
flags = 0;
@@ -224,7 +222,15 @@ main(int argc, char *argv[])
kore_log(LOG_NOTICE, "server shutting down");
kore_worker_shutdown();
- unlink(kore_pidfile);
+
+ rcall = kore_runtime_getcall("kore_parent_teardown");
+ if (rcall != NULL) {
+ kore_runtime_execute(rcall);
+ kore_free(rcall);
+ }
+
+ if (unlink(kore_pidfile) == -1 && errno != ENOENT)
+ kore_log(LOG_NOTICE, "failed to remove pidfile (%s)", errno_s);
kore_listener_cleanup();
kore_log(LOG_NOTICE, "goodbye");
diff --git a/src/worker.c b/src/worker.c
@@ -463,6 +463,12 @@ kore_worker_entry(struct kore_worker *kw)
break;
}
+ rcall = kore_runtime_getcall("kore_worker_teardown");
+ if (rcall != NULL) {
+ kore_runtime_execute(rcall);
+ kore_free(rcall);
+ }
+
kore_platform_event_cleanup();
kore_connection_cleanup();
kore_domain_cleanup();