diff options
author | Corey Farrell <git@cfware.com> | 2015-03-19 10:21:42 +0000 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2015-03-19 10:21:42 +0000 |
commit | 3aa0a869c2553f0f056c065947e0838e47a089b0 (patch) | |
tree | 1765bd16c1bd7ce699136042fe87a39e445a6318 /main/logger.c | |
parent | d48665950278b39f7c7f76f7e77572059243a086 (diff) |
logger: Apply default console logging when configuration cannot be loaded.
When logger.conf is missing or invalid enable console logging and display
an error message.
ASTERISK-24817 #close
Reported by: Corey Farrell
Review: https://reviewboard.asterisk.org/r/4497/
........
Merged revisions 433122 from http://svn.asterisk.org/svn/asterisk/branches/11
........
Merged revisions 433126 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433130 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/logger.c')
-rw-r--r-- | main/logger.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/main/logger.c b/main/logger.c index 2f69b1ab0..90fb7f2c0 100644 --- a/main/logger.c +++ b/main/logger.c @@ -359,7 +359,14 @@ static struct logchannel *make_logchannel(const char *channel, const char *compo return chan; } -static void init_logger_chain(int locked, const char *altconf) +/* \brief Read config, setup channels. + * \param locked The logchannels list is locked and this is a reload + * \param altconf Alternate configuration file to read. + * + * \retval 0 Success + * \retval -1 No config found or Failed + */ +static int init_logger_chain(int locked, const char *altconf) { struct logchannel *chan; struct ast_config *cfg; @@ -370,7 +377,7 @@ static void init_logger_chain(int locked, const char *altconf) display_callids = 1; if (!(cfg = ast_config_load2(S_OR(altconf, "logger.conf"), "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) { - return; + cfg = NULL; } /* delete our list of log channels */ @@ -391,16 +398,13 @@ static void init_logger_chain(int locked, const char *altconf) /* If no config file, we're fine, set default options. */ if (!cfg) { - if (errno) { - fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno)); - } else { - fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n"); - } if (!(chan = ast_calloc(1, sizeof(*chan)))) { - return; + fprintf(stderr, "Failed to initialize default logging\n"); + return -1; } chan->type = LOGTYPE_CONSOLE; chan->logmask = __LOG_WARNING | __LOG_NOTICE | __LOG_ERROR; + if (!locked) { AST_RWLIST_WRLOCK(&logchannels); } @@ -409,7 +413,8 @@ static void init_logger_chain(int locked, const char *altconf) if (!locked) { AST_RWLIST_UNLOCK(&logchannels); } - return; + + return -1; } if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) { @@ -490,6 +495,8 @@ static void init_logger_chain(int locked, const char *altconf) } ast_config_destroy(cfg); + + return 0; } void ast_child_verbose(int level, const char *fmt, ...) @@ -1401,6 +1408,7 @@ void logger_queue_start(void) int init_logger(void) { + int res; /* auto rotate if sig SIGXFSZ comes a-knockin */ sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL); @@ -1426,9 +1434,12 @@ int init_logger(void) ast_mkdir(ast_config_AST_LOG_DIR, 0777); /* create log channels */ - init_logger_chain(0 /* locked */, NULL); + res = init_logger_chain(0 /* locked */, NULL); ast_verb_update(); logger_initialized = 1; + if (res) { + ast_log(LOG_ERROR, "Errors detected in logger.conf. Default console logging is being used.\n"); + } return 0; } |