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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user