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.
This commit is contained in:
Joris Vink 2018-10-23 21:46:34 +02:00
parent fc5fc4f4ab
commit 892814e353
3 changed files with 17 additions and 3 deletions

View File

@ -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 **);

View File

@ -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");

View File

@ -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();