Author: coreyfarrell Date: Thu Mar 19 05:20:40 2015 New Revision: 433126 URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433126 Log: 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 Modified: branches/13/ (props changed) branches/13/main/logger.c Propchange: branches/13/ ------------------------------------------------------------------------------ Binary property 'branch-11-merged' - no diff available. Modified: branches/13/main/logger.c URL: http://svnview.digium.com/svn/asterisk/branches/13/main/logger.c?view=diff&rev=433126&r1=433125&r2=433126 ============================================================================== --- branches/13/main/logger.c (original) +++ branches/13/main/logger.c Thu Mar 19 05:20:40 2015 @@ -367,7 +367,14 @@ 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; @@ -378,7 +385,7 @@ 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 */ @@ -399,16 +406,13 @@ /* 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); } @@ -417,7 +421,8 @@ if (!locked) { AST_RWLIST_UNLOCK(&logchannels); } - return; + + return -1; } if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) { @@ -498,6 +503,8 @@ } ast_config_destroy(cfg); + + return 0; } void ast_child_verbose(int level, const char *fmt, ...) @@ -1409,6 +1416,7 @@ int init_logger(void) { + int res; /* auto rotate if sig SIGXFSZ comes a-knockin */ sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL); @@ -1434,9 +1442,12 @@ 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; } -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- svn-commits mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/svn-commits