[svn-commits] russell: branch russell/ast_verbose_threadstorage
r38404 - in /team/russell/a...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Thu Jul 27 22:26:14 MST 2006
Author: russell
Date: Fri Jul 28 00:26:13 2006
New Revision: 38404
URL: http://svn.digium.com/view/asterisk?rev=38404&view=rev
Log:
Re-add the close_logger() function and make it close all of the files the logger
opened, which it never did before. Also, convert the logchannels list to use
the linked list macros. There are also some little formatting tweaks mixed in.
Modified:
team/russell/ast_verbose_threadstorage/asterisk.c
team/russell/ast_verbose_threadstorage/include/asterisk.h
team/russell/ast_verbose_threadstorage/logger.c
Modified: team/russell/ast_verbose_threadstorage/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/asterisk.c?rev=38404&r1=38403&r2=38404&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/asterisk.c (original)
+++ team/russell/ast_verbose_threadstorage/asterisk.c Fri Jul 28 00:26:13 2006
@@ -1154,6 +1154,9 @@
ast_verbose("Restarting Asterisk NOW...\n");
restartnow = 1;
+ /* close logger */
+ close_logger();
+
/* If there is a consolethread running send it a SIGHUP
so it can execvp, otherwise we can do it ourselves */
if ((consolethread != AST_PTHREADT_NULL) && (consolethread != pthread_self())) {
@@ -1163,6 +1166,9 @@
} else
execvp(_argv[0], _argv);
+ } else {
+ /* close logger */
+ close_logger();
}
exit(0);
}
Modified: team/russell/ast_verbose_threadstorage/include/asterisk.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk.h?rev=38404&r1=38403&r2=38404&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk.h Fri Jul 28 00:26:13 2006
@@ -54,6 +54,7 @@
int load_modules(const int preload_only); /*!< Provided by module.c */
int load_pbx(void); /*!< Provided by pbx.c */
int init_logger(void); /*!< Provided by logger.c */
+void close_logger(void); /*!< Provided by logger.c */
int reload_logger(int); /*!< Provided by logger.c */
int init_framer(void); /*!< Provided by frame.c */
int term_init(void); /*!< Provided by term.c */
Modified: team/russell/ast_verbose_threadstorage/logger.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/logger.c?rev=38404&r1=38403&r2=38404&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/logger.c (original)
+++ team/russell/ast_verbose_threadstorage/logger.c Fri Jul 28 00:26:13 2006
@@ -84,7 +84,6 @@
static char dateformat[256] = "%b %e %T"; /* Original Asterisk Format */
-AST_MUTEX_DEFINE_STATIC(loglock);
static int filesize_reload_needed = 0;
static int global_logmask = -1;
@@ -108,10 +107,10 @@
enum logtypes type; /* Type of log channel */
FILE *fileptr; /* logfile logging file pointer */
char filename[256]; /* Filename */
- struct logchannel *next; /* Next channel in chain */
+ AST_LIST_ENTRY(logchannel) list;
};
-static struct logchannel *logchannels = NULL;
+static AST_LIST_HEAD_STATIC(logchannels, logchannel);
static FILE *eventlog = NULL;
static FILE *qlog = NULL;
@@ -284,21 +283,16 @@
static void init_logger_chain(void)
{
- struct logchannel *chan, *cur;
+ struct logchannel *chan;
struct ast_config *cfg;
struct ast_variable *var;
char *s;
/* delete our list of log channels */
- ast_mutex_lock(&loglock);
- chan = logchannels;
- while (chan) {
- cur = chan->next;
+ AST_LIST_LOCK(&logchannels);
+ while ((chan = AST_LIST_REMOVE_HEAD(&logchannels, list)))
free(chan);
- chan = cur;
- }
- logchannels = NULL;
- ast_mutex_unlock(&loglock);
+ AST_LIST_UNLOCK(&logchannels);
global_logmask = 0;
/* close syslog */
@@ -313,16 +307,16 @@
return;
chan->type = LOGTYPE_CONSOLE;
chan->logmask = 28; /*warning,notice,error */
- chan->next = logchannels;
- logchannels = chan;
+ AST_LIST_LOCK(&logchannels);
+ AST_LIST_INSERT_HEAD(&logchannels, chan, list);
+ AST_LIST_UNLOCK(&logchannels);
global_logmask |= chan->logmask;
return;
}
- ast_mutex_lock(&loglock);
if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
- if(ast_true(s)) {
- if(gethostname(hostname, sizeof(hostname)-1)) {
+ if (ast_true(s)) {
+ if (gethostname(hostname, sizeof(hostname) - 1)) {
ast_copy_string(hostname, "unknown", sizeof(hostname));
ast_log(LOG_WARNING, "What box has no hostname???\n");
}
@@ -330,34 +324,32 @@
hostname[0] = '\0';
} else
hostname[0] = '\0';
- if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
+ if ((s = ast_variable_retrieve(cfg, "general", "dateformat")))
ast_copy_string(dateformat, s, sizeof(dateformat));
- } else
+ else
ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
- if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
+ if ((s = ast_variable_retrieve(cfg, "general", "queue_log")))
logfiles.queue_log = ast_true(s);
- }
- if ((s = ast_variable_retrieve(cfg, "general", "event_log"))) {
+ if ((s = ast_variable_retrieve(cfg, "general", "event_log")))
logfiles.event_log = ast_true(s);
- }
-
+
+ AST_LIST_LOCK(&logchannels);
var = ast_variable_browse(cfg, "logfiles");
for (; var; var = var->next) {
if (!(chan = make_logchannel(var->name, var->value, var->lineno)))
continue;
- chan->next = logchannels;
- logchannels = chan;
+ AST_LIST_INSERT_HEAD(&logchannels, chan, list);
global_logmask |= chan->logmask;
}
+ AST_LIST_UNLOCK(&logchannels);
ast_config_destroy(cfg);
- ast_mutex_unlock(&loglock);
}
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
{
va_list ap;
- ast_mutex_lock(&loglock);
+ AST_LIST_LOCK(&logchannels);
if (qlog) {
va_start(ap, fmt);
fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
@@ -366,7 +358,7 @@
va_end(ap);
fflush(qlog);
}
- ast_mutex_unlock(&loglock);
+ AST_LIST_UNLOCK(&logchannels);
}
int reload_logger(int rotate)
@@ -378,7 +370,8 @@
FILE *myf;
int x, res = 0;
- ast_mutex_lock(&loglock);
+ AST_LIST_LOCK(&logchannels);
+
if (eventlog)
fclose(eventlog);
else
@@ -393,8 +386,7 @@
mkdir((char *)ast_config_AST_LOG_DIR, 0755);
- f = logchannels;
- while(f) {
+ AST_LIST_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);
@@ -402,17 +394,16 @@
if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
fclose(f->fileptr); /* Close file */
f->fileptr = NULL;
- if(rotate) {
+ if (rotate) {
ast_copy_string(old, f->filename, sizeof(old));
- for(x=0;;x++) {
+ for (x = 0; ; x++) {
snprintf(new, sizeof(new), "%s.%d", f->filename, x);
myf = fopen((char *)new, "r");
- if (myf) {
+ if (myf)
fclose(myf);
- } else {
+ else
break;
- }
}
/* do it */
@@ -420,7 +411,6 @@
fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
}
}
- f = f->next;
}
filesize_reload_needed = 0;
@@ -483,7 +473,8 @@
res = -1;
}
}
- ast_mutex_unlock(&loglock);
+
+ AST_LIST_UNLOCK(&logchannels);
return res;
}
@@ -512,14 +503,12 @@
#define FORMATL "%-35.35s %-8.8s %-9.9s "
struct logchannel *chan;
- ast_mutex_lock(&loglock);
-
- chan = logchannels;
ast_cli(fd,FORMATL, "Channel", "Type", "Status");
ast_cli(fd, "Configuration\n");
ast_cli(fd,FORMATL, "-------", "----", "------");
ast_cli(fd, "-------------\n");
- while (chan) {
+ AST_LIST_LOCK(&logchannels);
+ AST_LIST_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, " - ");
@@ -538,11 +527,9 @@
if (chan->logmask & (1 << __LOG_EVENT))
ast_cli(fd, "Event ");
ast_cli(fd, "\n");
- chan = chan->next;
- }
+ }
+ AST_LIST_UNLOCK(&logchannels);
ast_cli(fd, "\n");
-
- ast_mutex_unlock(&loglock);
return RESULT_SUCCESS;
}
@@ -629,6 +616,36 @@
return res;
}
+void close_logger(void)
+{
+ struct logchannel *f;
+
+ AST_LIST_LOCK(&logchannels);
+
+ if (eventlog) {
+ fclose(eventlog);
+ eventlog = NULL;
+ }
+
+ if (qlog) {
+ fclose(qlog);
+ qlog = NULL;
+ }
+
+ AST_LIST_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);
+
+ return;
+}
+
static void ast_log_vsyslog(int level, const char *file, int line, const char *function, const char *fmt, va_list args)
{
char buf[BUFSIZ];
@@ -686,13 +703,12 @@
if ((level == __LOG_DEBUG) && !ast_strlen_zero(debug_filename) && strcasecmp(debug_filename, file))
return;
- /* begin critical section */
- ast_mutex_lock(&loglock);
-
time(&t);
localtime_r(&t, &tm);
strftime(date, sizeof(date), dateformat, &tm);
+ AST_LIST_LOCK(&logchannels);
+
if (logfiles.event_log && level == __LOG_EVENT) {
va_start(ap, fmt);
@@ -701,13 +717,14 @@
fflush(eventlog);
va_end(ap);
- ast_mutex_unlock(&loglock);
+ AST_LIST_UNLOCK(&logchannels);
return;
}
- if (logchannels) {
- chan = logchannels;
- while(chan && !chan->disabled) {
+ if (!AST_LIST_EMPTY(&logchannels)) {
+ AST_LIST_TRAVERSE(&logchannels, chan, list) {
+ if (chan->disabled)
+ break;
/* Check syslog channels */
if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << level))) {
va_start(ap, fmt);
@@ -758,7 +775,6 @@
fflush(chan->fileptr);
}
}
- chan = chan->next;
}
} else {
/*
@@ -773,8 +789,8 @@
}
}
- ast_mutex_unlock(&loglock);
- /* end critical section */
+ AST_LIST_UNLOCK(&logchannels);
+
if (filesize_reload_needed) {
reload_logger(1);
ast_log(LOG_EVENT,"Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
More information about the svn-commits
mailing list