Skip to content

Commit

Permalink
[core] fix printing cfg file context for errors after a reload_routes
Browse files Browse the repository at this point in the history
Reset the file context list each time a new cfg parsing starts, to be sure we do not inherite the context from a previous parsing.
If we do not do this, when doing a reload_routes, if an parsing error occurs, we will get references and dumps (of the faulty lines) from the original, startup script, not from the reloaded one.

(cherry picked from commit 52e5180)
  • Loading branch information
bogdan-iancu committed Nov 2, 2021
1 parent 7ea9b66 commit 41d57ac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cfg_pp.c
Expand Up @@ -57,6 +57,7 @@ static int exec_preprocessor(FILE *flat_cfg, const char *preproc_cmdline,
str *out);

static struct cfg_context *cfg_context_new_file(const char *path);
static void cfg_context_reset_all(void);
static void cfg_context_append_line(struct cfg_context *con,
char *line, int len);

Expand All @@ -82,6 +83,8 @@ int parse_opensips_cfg(const char *cfg_file, const char *preproc_cmdline,
}
}

cfg_context_reset_all();

if (flatten_opensips_cfg(cfg_stream,
cfg_stream == stdin ? "stdin" : cfg_file, &cfg_buf) < 0) {
LM_ERR("failed to resolve file imports for %s\n", cfg_file);
Expand Down Expand Up @@ -248,6 +251,21 @@ static struct cfg_context {
struct cfg_context *next;
} *__ccon;

static void cfg_context_reset_all(void)
{
struct cfg_context *pos = NULL, *it = __ccon;

while ( it && (it != __ccon || !pos) ) {
pos = it;
it = it->next;
free((char*)pos->path);
free((char*)pos->dirname);
free(pos->lines);
free(pos);
};
__ccon = NULL;
}

static struct cfg_context *cfg_context_new_file(const char *path)
{
struct cfg_context *con, *it;
Expand Down

0 comments on commit 41d57ac

Please sign in to comment.