Skip to content

Commit

Permalink
dialog: fix a runtime bug with DLGCB_LOADED callbacks
Browse files Browse the repository at this point in the history
Relying on the fact that all modules that register dialog callbacks are initialised
after the dialog module (thanks to module dependencies), we can run all DLGCB_LOADED
callbacks at registration time and also keep them in a list for calling them later
(i.e reloading from database via MI cmd or receiving replicated dialog).

This fixes a series of bugs where the DLGCB_LOADED callback is not run during, e.g.
"dlg_db_sync" MI command or received replicated dialogs which do not have their
callbacks installed or run.

(cherry picked from commit 8c8f27f)
  • Loading branch information
rvlad-patrascu committed Oct 16, 2017
1 parent caf912d commit b18a61e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 0 additions & 2 deletions modules/dialog/dialog.c
Expand Up @@ -961,10 +961,8 @@ static int mod_init(void)
LM_ERR("failed to initialize the DB support\n");
return -1;
}
run_load_callbacks();
}

mark_dlg_loaded_callbacks_run();
destroy_cachedb(0);

return 0;
Expand Down
14 changes: 3 additions & 11 deletions modules/dialog/dlg_cb.c
Expand Up @@ -36,7 +36,6 @@

static struct dlg_head_cbl* create_cbs = 0;

static int dlg_load_cbs_run = 0;
static struct dlg_head_cbl* load_cbs = 0;

static struct dlg_cb_params params = {NULL, DLG_DIR_NONE, NULL, NULL};
Expand Down Expand Up @@ -80,11 +79,6 @@ void destroy_dlg_callbacks_list(struct dlg_callback *cb)
}
}

void mark_dlg_loaded_callbacks_run(void)
{
dlg_load_cbs_run = 1;
}


void destroy_dlg_callbacks(unsigned int types)
{
Expand Down Expand Up @@ -161,11 +155,9 @@ int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f,
create_cbs->first = cb;
create_cbs->types |= types;
} else if (types==DLGCB_LOADED) {
if (dlg_load_cbs_run) {
/* run the callback on the spot */
run_load_callback(cb);
return 0;
}
/* run the callback on the spot */
run_load_callback(cb);
/* also insert callback in list to be able to run it later */
if (load_cbs==0) {
/* not initialized yet */
if ( (load_cbs=init_dlg_callback())==NULL ) {
Expand Down

0 comments on commit b18a61e

Please sign in to comment.