Introduce our own shutdown callback mechanism.

Instead of adding stuff to `_shutdown()`, we can now register a shutdown
routine from the respective `init()` function of our modules.

This also has the advantage, that we're sure they're called in reverse
order from how the initialization happened.

I didn't simply use `atexit()` because POSIX says that the number of
possible callbacks is limited (min 32) and I was not sure whether
we will maybe extend this number at one point.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2025-03-07 11:44:31 +01:00
parent 662a0be633
commit c5a131ee46
39 changed files with 321 additions and 327 deletions

View File

@@ -99,10 +99,25 @@ static char* saved_status;
static void _session_free_internals(void);
static void _session_free_saved_details(void);
static void
_session_shutdown(void)
{
_session_free_internals();
chat_sessions_clear();
presence_sub_requests_destroy();
connection_shutdown();
if (saved_status) {
free(saved_status);
}
}
void
session_init(void)
{
log_info("Initialising XMPP");
prof_add_shutdown_routine(_session_shutdown);
connection_init();
presence_sub_requests_init();
caps_init();
@@ -227,20 +242,6 @@ session_disconnect(void)
connection_set_disconnected();
}
void
session_shutdown(void)
{
_session_free_internals();
chat_sessions_clear();
presence_sub_requests_destroy();
connection_shutdown();
if (saved_status) {
free(saved_status);
}
}
void
session_process_events(void)
{