mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 03:59:01 +00:00
Refactor init_logger_chain locking.
This removes logchannels locking from init_logger_chain, puts the responsibility on the caller. Adds locking around the one call that was missing it. ASTERISK-24833 Change-Id: I6cc42117338bf9575650a67bcb78ab1a33d7bad8
This commit is contained in:
@@ -560,13 +560,14 @@ static struct logchannel *make_logchannel(const char *channel, const char *compo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* \brief Read config, setup channels.
|
/* \brief Read config, setup channels.
|
||||||
* \param locked The logchannels list is locked and this is a reload
|
|
||||||
* \param altconf Alternate configuration file to read.
|
* \param altconf Alternate configuration file to read.
|
||||||
*
|
*
|
||||||
|
* \pre logchannels list is write locked
|
||||||
|
*
|
||||||
* \retval 0 Success
|
* \retval 0 Success
|
||||||
* \retval -1 No config found or Failed
|
* \retval -1 No config found or Failed
|
||||||
*/
|
*/
|
||||||
static int init_logger_chain(int locked, const char *altconf)
|
static int init_logger_chain(const char *altconf)
|
||||||
{
|
{
|
||||||
struct logchannel *chan;
|
struct logchannel *chan;
|
||||||
struct ast_config *cfg;
|
struct ast_config *cfg;
|
||||||
@@ -578,10 +579,6 @@ static int init_logger_chain(int locked, const char *altconf)
|
|||||||
cfg = NULL;
|
cfg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locked) {
|
|
||||||
AST_RWLIST_WRLOCK(&logchannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set defaults */
|
/* Set defaults */
|
||||||
hostname[0] = '\0';
|
hostname[0] = '\0';
|
||||||
display_callids = 1;
|
display_callids = 1;
|
||||||
@@ -597,9 +594,6 @@ static int init_logger_chain(int locked, const char *altconf)
|
|||||||
ast_free(chan);
|
ast_free(chan);
|
||||||
}
|
}
|
||||||
global_logmask = 0;
|
global_logmask = 0;
|
||||||
if (!locked) {
|
|
||||||
AST_RWLIST_UNLOCK(&logchannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
/* close syslog */
|
/* close syslog */
|
||||||
@@ -615,14 +609,8 @@ static int init_logger_chain(int locked, const char *altconf)
|
|||||||
chan->logmask = __LOG_WARNING | __LOG_NOTICE | __LOG_ERROR;
|
chan->logmask = __LOG_WARNING | __LOG_NOTICE | __LOG_ERROR;
|
||||||
memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
|
memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
|
||||||
|
|
||||||
if (!locked) {
|
|
||||||
AST_RWLIST_WRLOCK(&logchannels);
|
|
||||||
}
|
|
||||||
AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
|
AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
|
||||||
global_logmask |= chan->logmask;
|
global_logmask |= chan->logmask;
|
||||||
if (!locked) {
|
|
||||||
AST_RWLIST_UNLOCK(&logchannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -675,9 +663,6 @@ static int init_logger_chain(int locked, const char *altconf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locked) {
|
|
||||||
AST_RWLIST_WRLOCK(&logchannels);
|
|
||||||
}
|
|
||||||
var = ast_variable_browse(cfg, "logfiles");
|
var = ast_variable_browse(cfg, "logfiles");
|
||||||
for (; var; var = var->next) {
|
for (; var; var = var->next) {
|
||||||
if (!(chan = make_logchannel(var->name, var->value, var->lineno, 0))) {
|
if (!(chan = make_logchannel(var->name, var->value, var->lineno, 0))) {
|
||||||
@@ -697,10 +682,6 @@ static int init_logger_chain(int locked, const char *altconf)
|
|||||||
qlog = NULL;
|
qlog = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locked) {
|
|
||||||
AST_RWLIST_UNLOCK(&logchannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
ast_config_destroy(cfg);
|
ast_config_destroy(cfg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1055,7 +1036,7 @@ static int reload_logger(int rotate, const char *altconf)
|
|||||||
|
|
||||||
filesize_reload_needed = 0;
|
filesize_reload_needed = 0;
|
||||||
|
|
||||||
init_logger_chain(1 /* locked */, altconf);
|
init_logger_chain(altconf);
|
||||||
|
|
||||||
ast_unload_realtime("queue_log");
|
ast_unload_realtime("queue_log");
|
||||||
if (logfiles.queue_log) {
|
if (logfiles.queue_log) {
|
||||||
@@ -1153,7 +1134,7 @@ int ast_logger_rotate_channel(const char *log_channel)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_logger_chain(1 /* locked */, NULL);
|
init_logger_chain(NULL);
|
||||||
|
|
||||||
AST_RWLIST_UNLOCK(&logchannels);
|
AST_RWLIST_UNLOCK(&logchannels);
|
||||||
|
|
||||||
@@ -1725,7 +1706,9 @@ int init_logger(void)
|
|||||||
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
|
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
|
||||||
|
|
||||||
/* create log channels */
|
/* create log channels */
|
||||||
res = init_logger_chain(0 /* locked */, NULL);
|
AST_RWLIST_WRLOCK(&logchannels);
|
||||||
|
res = init_logger_chain(NULL);
|
||||||
|
AST_RWLIST_UNLOCK(&logchannels);
|
||||||
ast_verb_update();
|
ast_verb_update();
|
||||||
logger_initialized = 1;
|
logger_initialized = 1;
|
||||||
if (res) {
|
if (res) {
|
||||||
|
Reference in New Issue
Block a user