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:
@@ -61,10 +61,22 @@ static Autocomplete enabled_ac;
|
||||
|
||||
static void _save_accounts(void);
|
||||
|
||||
static void
|
||||
_accounts_close(void)
|
||||
{
|
||||
autocomplete_free(all_ac);
|
||||
autocomplete_free(enabled_ac);
|
||||
free_keyfile(&accounts_prof_keyfile);
|
||||
accounts = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
accounts_load(void)
|
||||
{
|
||||
log_info("Loading accounts");
|
||||
|
||||
prof_add_shutdown_routine(_accounts_close);
|
||||
|
||||
all_ac = autocomplete_new();
|
||||
enabled_ac = autocomplete_new();
|
||||
load_data_keyfile(&accounts_prof_keyfile, FILE_ACCOUNTS);
|
||||
@@ -82,15 +94,6 @@ accounts_load(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
accounts_close(void)
|
||||
{
|
||||
autocomplete_free(all_ac);
|
||||
autocomplete_free(enabled_ac);
|
||||
free_keyfile(&accounts_prof_keyfile);
|
||||
accounts = NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
accounts_find_enabled(const char* const prefix, gboolean previous, void* context)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user