Skip to content

Commit

Permalink
Fix persistency of the globally set log_level
Browse files Browse the repository at this point in the history
The globally set log_level (via MI cmd) must impact the future forked processes (due to auto scalling).
Closes #3146

(cherry picked from commit 9425098)
  • Loading branch information
bogdan-iancu committed Oct 9, 2023
1 parent f71fe69 commit b40bced
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions dprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

static int log_level_holder = L_NOTICE;

/* shared holder with the globally set log_level */
static int *log_level_global = NULL;

/* current logging level for this process */
int *log_level = &log_level_holder;

Expand Down Expand Up @@ -96,9 +99,20 @@ void dprint(char * format, ...)
int init_log_level(void)
{
log_level = &pt[process_no].log_level;
*log_level = log_level_holder;
default_log_level = &pt[process_no].default_log_level;
*default_log_level = log_level_holder;

if (process_no==0) {
/* this is done only by the first process */
log_level_global = (int*)shm_malloc(sizeof(int));
if (log_level_global==NULL) {
LM_ERR("Failed to allocate shm memory for global log_level\n");
return -1;
}
*log_level_global = log_level_holder;
}

*log_level = *log_level_global;
*default_log_level = *log_level_global;

return 0;
}
Expand Down Expand Up @@ -142,6 +156,7 @@ void set_global_log_level(int level)
__set_proc_default_log_level(i, level);
__set_proc_log_level(i, level);
}
*log_level_global = level;
}

/* set the log level of the current process */
Expand Down

0 comments on commit b40bced

Please sign in to comment.