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

@@ -116,10 +116,23 @@ static struct omemo_static_data
GHashTable* fingerprint_ac;
} omemo_static_data;
static void
_omemo_close(void)
{
if (omemo_static_data.fingerprint_ac) {
g_hash_table_destroy(omemo_static_data.fingerprint_ac);
omemo_static_data.fingerprint_ac = NULL;
}
pthread_mutex_destroy(&omemo_static_data.lock);
}
void
omemo_init(void)
{
log_info("[OMEMO] initialising");
prof_add_shutdown_routine(_omemo_close);
if (omemo_crypto_init() != 0) {
cons_show("Error initializing OMEMO crypto: gcry_check_version() failed");
}
@@ -131,16 +144,6 @@ omemo_init(void)
omemo_static_data.fingerprint_ac = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)autocomplete_free);
}
void
omemo_close(void)
{
if (omemo_static_data.fingerprint_ac) {
g_hash_table_destroy(omemo_static_data.fingerprint_ac);
omemo_static_data.fingerprint_ac = NULL;
}
pthread_mutex_destroy(&omemo_static_data.lock);
}
void
omemo_on_connect(ProfAccount* account)
{

View File

@@ -61,7 +61,6 @@ typedef struct omemo_key
} omemo_key_t;
void omemo_init(void);
void omemo_close(void);
void omemo_on_connect(ProfAccount* account);
void omemo_on_disconnect(void);
void omemo_generate_crypto_materials(ProfAccount* account);