AST_LIST_ENTRY(logchannel) list;
};
-static AST_LIST_HEAD_STATIC(logchannels, logchannel);
+static AST_RWLIST_HEAD_STATIC(logchannels, logchannel);
enum logmsgtypes {
LOGMSG_NORMAL = 0,
const char *s;
/* delete our list of log channels */
- AST_LIST_LOCK(&logchannels);
- while ((chan = AST_LIST_REMOVE_HEAD(&logchannels, list)))
+ AST_RWLIST_WRLOCK(&logchannels);
+ while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list)))
free(chan);
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
global_logmask = 0;
errno = 0;
return;
chan->type = LOGTYPE_CONSOLE;
chan->logmask = 28; /*warning,notice,error */
- AST_LIST_LOCK(&logchannels);
- AST_LIST_INSERT_HEAD(&logchannels, chan, list);
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_WRLOCK(&logchannels);
+ AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
+ AST_RWLIST_UNLOCK(&logchannels);
global_logmask |= chan->logmask;
return;
}
if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp")))
rotatetimestamp = ast_true(s);
- AST_LIST_LOCK(&logchannels);
+ AST_RWLIST_WRLOCK(&logchannels);
var = ast_variable_browse(cfg, "logfiles");
for (; var; var = var->next) {
if (!(chan = make_logchannel(var->name, var->value, var->lineno)))
continue;
- AST_LIST_INSERT_HEAD(&logchannels, chan, list);
+ AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
global_logmask |= chan->logmask;
}
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
ast_config_destroy(cfg);
}
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
{
va_list ap;
- AST_LIST_LOCK(&logchannels);
+ char qlog_msg[8192];
+ int qlog_len;
if (qlog) {
va_start(ap, fmt);
- fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
- vfprintf(qlog, fmt, ap);
- fprintf(qlog, "\n");
+ qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
+ vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
va_end(ap);
+ }
+ AST_RWLIST_RDLOCK(&logchannels);
+ if (qlog) {
+ fprintf(qlog, "%s\n", qlog_msg);
fflush(qlog);
}
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
}
int reload_logger(int rotate)
FILE *myf;
int x, res = 0;
- AST_LIST_LOCK(&logchannels);
+ AST_RWLIST_WRLOCK(&logchannels);
if (eventlog)
fclose(eventlog);
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
- AST_LIST_TRAVERSE(&logchannels, f, list) {
+ AST_RWLIST_TRAVERSE(&logchannels, f, list) {
if (f->disabled) {
f->disabled = 0; /* Re-enable logging at reload */
manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
}
}
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
return res;
}
ast_cli(fd, "Configuration\n");
ast_cli(fd,FORMATL, "-------", "----", "------");
ast_cli(fd, "-------------\n");
- AST_LIST_LOCK(&logchannels);
- AST_LIST_TRAVERSE(&logchannels, chan, list) {
+ AST_RWLIST_RDLOCK(&logchannels);
+ AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"),
chan->disabled ? "Disabled" : "Enabled");
ast_cli(fd, " - ");
ast_cli(fd, "Event ");
ast_cli(fd, "\n");
}
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
ast_cli(fd, "\n");
return RESULT_SUCCESS;
AST_LIST_ENTRY(verb) list;
};
-static AST_LIST_HEAD_STATIC(verbosers, verb);
+static AST_RWLIST_HEAD_STATIC(verbosers, verb);
static char logger_reload_help[] =
"Usage: logger reload\n"
struct logchannel *chan = NULL;
char buf[BUFSIZ];
- AST_LIST_LOCK(&logchannels);
+ AST_RWLIST_RDLOCK(&logchannels);
if (logfiles.event_log && logmsg->level == __LOG_EVENT) {
fprintf(eventlog, "%s asterisk[%ld]: %s", logmsg->date, (long)getpid(), logmsg->str);
fflush(eventlog);
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
return;
}
- if (!AST_LIST_EMPTY(&logchannels)) {
- AST_LIST_TRAVERSE(&logchannels, chan, list) {
+ if (!AST_RWLIST_EMPTY(&logchannels)) {
+ AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
/* If the channel is disabled, then move on to the next one */
if (chan->disabled)
continue;
fputs(logmsg->str, stdout);
}
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
/* If we need to reload because of the file size, then do so */
if (filesize_reload_needed) {
struct verb *v = NULL;
/* Iterate through the list of verbosers and pass them the log message string */
- AST_LIST_LOCK(&verbosers);
- AST_LIST_TRAVERSE(&verbosers, v, list)
+ AST_RWLIST_RDLOCK(&verbosers);
+ AST_RWLIST_TRAVERSE(&verbosers, v, list)
v->verboser(logmsg->str);
- AST_LIST_UNLOCK(&verbosers);
+ AST_RWLIST_UNLOCK(&verbosers);
return;
}
ast_cond_signal(&logcond);
AST_LIST_UNLOCK(&logmsgs);
- AST_LIST_LOCK(&logchannels);
+ AST_RWLIST_WRLOCK(&logchannels);
if (eventlog) {
fclose(eventlog);
qlog = NULL;
}
- AST_LIST_TRAVERSE(&logchannels, f, list) {
+ AST_RWLIST_TRAVERSE(&logchannels, f, list) {
if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
fclose(f->fileptr);
f->fileptr = NULL;
closelog(); /* syslog */
- AST_LIST_UNLOCK(&logchannels);
+ AST_RWLIST_UNLOCK(&logchannels);
return;
}
if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
return;
- if (AST_LIST_EMPTY(&logchannels)) {
+ if (AST_RWLIST_EMPTY(&logchannels)) {
/*
* we don't have the logger chain configured yet,
* so just log to stdout
verb->verboser = v;
- AST_LIST_LOCK(&verbosers);
- AST_LIST_INSERT_HEAD(&verbosers, verb, list);
- AST_LIST_UNLOCK(&verbosers);
+ AST_RWLIST_WRLOCK(&verbosers);
+ AST_RWLIST_INSERT_HEAD(&verbosers, verb, list);
+ AST_RWLIST_UNLOCK(&verbosers);
return 0;
}
{
struct verb *cur;
- AST_LIST_LOCK(&verbosers);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
+ AST_RWLIST_WRLOCK(&verbosers);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
if (cur->verboser == v) {
- AST_LIST_REMOVE_CURRENT(&verbosers, list);
+ AST_RWLIST_REMOVE_CURRENT(&verbosers, list);
free(cur);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
- AST_LIST_UNLOCK(&verbosers);
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&verbosers);
return cur ? 0 : -1;
}