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:
@@ -69,10 +69,26 @@ static EntityCapabilities* _caps_by_ver(const char* const ver);
|
||||
static EntityCapabilities* _caps_by_jid(const char* const jid);
|
||||
static EntityCapabilities* _caps_copy(EntityCapabilities* caps);
|
||||
|
||||
static void
|
||||
_caps_close(void)
|
||||
{
|
||||
free_keyfile(&caps_prof_keyfile);
|
||||
cache = NULL;
|
||||
g_hash_table_destroy(jid_to_ver);
|
||||
g_hash_table_destroy(jid_to_caps);
|
||||
g_free(cache_loc);
|
||||
cache_loc = NULL;
|
||||
g_hash_table_destroy(prof_features);
|
||||
prof_features = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
caps_init(void)
|
||||
{
|
||||
log_info("Loading capabilities cache");
|
||||
|
||||
prof_add_shutdown_routine(_caps_close);
|
||||
|
||||
load_data_keyfile(&caps_prof_keyfile, FILE_CAPSCACHE);
|
||||
cache = caps_prof_keyfile.keyfile;
|
||||
|
||||
@@ -339,19 +355,6 @@ caps_reset_ver(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
caps_close(void)
|
||||
{
|
||||
free_keyfile(&caps_prof_keyfile);
|
||||
cache = NULL;
|
||||
g_hash_table_destroy(jid_to_ver);
|
||||
g_hash_table_destroy(jid_to_caps);
|
||||
g_free(cache_loc);
|
||||
cache_loc = NULL;
|
||||
g_hash_table_destroy(prof_features);
|
||||
prof_features = NULL;
|
||||
}
|
||||
|
||||
static EntityCapabilities*
|
||||
_caps_by_ver(const char* const ver)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user