Move syslog utility functions into a separate file so they can be re-used.
[asterisk/asterisk.git] / main / logger.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Asterisk Logger
22  *
23  * Logging routines
24  *
25  * \author Mark Spencer <markster@digium.com>
26  */
27
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 /* When we include logger.h again it will trample on some stuff in syslog.h, but
33  * nothing we care about in here. */
34 #include <syslog.h>
35
36 #include "asterisk/_private.h"
37 #include "asterisk/paths.h"     /* use ast_config_AST_LOG_DIR */
38 #include "asterisk/logger.h"
39 #include "asterisk/lock.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/config.h"
42 #include "asterisk/term.h"
43 #include "asterisk/cli.h"
44 #include "asterisk/utils.h"
45 #include "asterisk/manager.h"
46 #include "asterisk/threadstorage.h"
47 #include "asterisk/strings.h"
48 #include "asterisk/pbx.h"
49 #include "asterisk/app.h"
50 #include "asterisk/syslog.h"
51
52 #include <signal.h>
53 #include <time.h>
54 #include <sys/stat.h>
55 #include <fcntl.h>
56 #ifdef HAVE_BKTR
57 #include <execinfo.h>
58 #define MAX_BACKTRACE_FRAMES 20
59 #endif
60
61 #if defined(__linux__) && !defined(__NR_gettid)
62 #include <asm/unistd.h>
63 #endif
64
65 #if defined(__linux__) && defined(__NR_gettid)
66 #define GETTID() syscall(__NR_gettid)
67 #else
68 #define GETTID() getpid()
69 #endif
70 static char dateformat[256] = "%b %e %T";               /* Original Asterisk Format */
71
72 static char queue_log_name[256] = QUEUELOG;
73 static char exec_after_rotate[256] = "";
74
75 static int filesize_reload_needed;
76 static unsigned int global_logmask = 0xFFFF;
77
78 static enum rotatestrategy {
79         SEQUENTIAL = 1 << 0,     /* Original method - create a new file, in order */
80         ROTATE = 1 << 1,         /* Rotate all files, such that the oldest file has the highest suffix */
81         TIMESTAMP = 1 << 2,      /* Append the epoch timestamp onto the end of the archived file */
82 } rotatestrategy = SEQUENTIAL;
83
84 static struct {
85         unsigned int queue_log:1;
86 } logfiles = { 1 };
87
88 static char hostname[MAXHOSTNAMELEN];
89
90 enum logtypes {
91         LOGTYPE_SYSLOG,
92         LOGTYPE_FILE,
93         LOGTYPE_CONSOLE,
94 };
95
96 struct logchannel {
97         /*! What to log to this channel */
98         unsigned int logmask;
99         /*! If this channel is disabled or not */
100         int disabled;
101         /*! syslog facility */
102         int facility;
103         /*! Type of log channel */
104         enum logtypes type;
105         /*! logfile logging file pointer */
106         FILE *fileptr;
107         /*! Filename */
108         char filename[PATH_MAX];
109         /*! field for linking to list */
110         AST_LIST_ENTRY(logchannel) list;
111         /*! Line number from configuration file */
112         int lineno;
113         /*! Components (levels) from last config load */
114         char components[0];
115 };
116
117 static AST_RWLIST_HEAD_STATIC(logchannels, logchannel);
118
119 enum logmsgtypes {
120         LOGMSG_NORMAL = 0,
121         LOGMSG_VERBOSE,
122 };
123
124 struct logmsg {
125         enum logmsgtypes type;
126         int level;
127         int line;
128         long process_id;
129         AST_DECLARE_STRING_FIELDS(
130                 AST_STRING_FIELD(date);
131                 AST_STRING_FIELD(file);
132                 AST_STRING_FIELD(function);
133                 AST_STRING_FIELD(message);
134                 AST_STRING_FIELD(level_name);
135         );
136         AST_LIST_ENTRY(logmsg) list;
137 };
138
139 static AST_LIST_HEAD_STATIC(logmsgs, logmsg);
140 static pthread_t logthread = AST_PTHREADT_NULL;
141 static ast_cond_t logcond;
142 static int close_logger_thread;
143
144 static FILE *qlog;
145
146 /*! \brief Logging channels used in the Asterisk logging system
147  *
148  * The first 16 levels are reserved for system usage, and the remaining
149  * levels are reserved for usage by dynamic levels registered via
150  * ast_logger_register_level.
151  */
152
153 /* Modifications to this array are protected by the rwlock in the
154  * logchannels list.
155  */
156
157 static char *levels[32] = {
158         "DEBUG",
159         "---EVENT---",          /* no longer used */
160         "NOTICE",
161         "WARNING",
162         "ERROR",
163         "VERBOSE",
164         "DTMF",
165 };
166
167 /*! \brief Colors used in the console for logging */
168 static const int colors[32] = {
169         COLOR_BRGREEN,
170         COLOR_BRBLUE,           /* no longer used */
171         COLOR_YELLOW,
172         COLOR_BRRED,
173         COLOR_RED,
174         COLOR_GREEN,
175         COLOR_BRGREEN,
176         0,
177         0,
178         0,
179         0,
180         0,
181         0,
182         0,
183         0,
184         0,
185         COLOR_BRBLUE,
186         COLOR_BRBLUE,
187         COLOR_BRBLUE,
188         COLOR_BRBLUE,
189         COLOR_BRBLUE,
190         COLOR_BRBLUE,
191         COLOR_BRBLUE,
192         COLOR_BRBLUE,
193         COLOR_BRBLUE,
194         COLOR_BRBLUE,
195         COLOR_BRBLUE,
196         COLOR_BRBLUE,
197         COLOR_BRBLUE,
198         COLOR_BRBLUE,
199         COLOR_BRBLUE,
200         COLOR_BRBLUE,
201 };
202
203 AST_THREADSTORAGE(verbose_buf);
204 #define VERBOSE_BUF_INIT_SIZE   256
205
206 AST_THREADSTORAGE(log_buf);
207 #define LOG_BUF_INIT_SIZE       256
208
209 static unsigned int make_components(const char *s, int lineno)
210 {
211         char *w;
212         unsigned int res = 0;
213         char *stringp = ast_strdupa(s);
214         unsigned int x;
215
216         while ((w = strsep(&stringp, ","))) {
217                 int found = 0;
218
219                 w = ast_skip_blanks(w);
220
221                 for (x = 0; x < ARRAY_LEN(levels); x++) {
222                         if (levels[x] && !strcasecmp(w, levels[x])) {
223                                 res |= (1 << x);
224                                 found = 1;
225                                 break;
226                         }
227                 }
228         }
229
230         return res;
231 }
232
233 static struct logchannel *make_logchannel(const char *channel, const char *components, int lineno)
234 {
235         struct logchannel *chan;
236         char *facility;
237
238         if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan) + strlen(components) + 1)))
239                 return NULL;
240
241         strcpy(chan->components, components);
242         chan->lineno = lineno;
243
244         if (!strcasecmp(channel, "console")) {
245                 chan->type = LOGTYPE_CONSOLE;
246         } else if (!strncasecmp(channel, "syslog", 6)) {
247                 /*
248                 * syntax is:
249                 *  syslog.facility => level,level,level
250                 */
251                 facility = strchr(channel, '.');
252                 if (!facility++ || !facility) {
253                         facility = "local0";
254                 }
255
256                 chan->facility = ast_syslog_facility(facility);
257
258                 if (chan->facility < 0) {
259                         fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
260                         ast_free(chan);
261                         return NULL;
262                 }
263
264                 chan->type = LOGTYPE_SYSLOG;
265                 ast_copy_string(chan->filename, channel, sizeof(chan->filename));
266                 openlog("asterisk", LOG_PID, chan->facility);
267         } else {
268                 if (!ast_strlen_zero(hostname)) {
269                         snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",
270                                  channel[0] != '/' ? ast_config_AST_LOG_DIR : "", channel, hostname);
271                 } else {
272                         snprintf(chan->filename, sizeof(chan->filename), "%s/%s",
273                                  channel[0] != '/' ? ast_config_AST_LOG_DIR : "", channel);
274                 }
275                 if (!(chan->fileptr = fopen(chan->filename, "a"))) {
276                         /* Can't log here, since we're called with a lock */
277                         fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno));
278                 } 
279                 chan->type = LOGTYPE_FILE;
280         }
281         chan->logmask = make_components(chan->components, lineno);
282
283         return chan;
284 }
285
286 static void init_logger_chain(int locked)
287 {
288         struct logchannel *chan;
289         struct ast_config *cfg;
290         struct ast_variable *var;
291         const char *s;
292         struct ast_flags config_flags = { 0 };
293
294         if (!(cfg = ast_config_load2("logger.conf", "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID)
295                 return;
296
297         /* delete our list of log channels */
298         if (!locked)
299                 AST_RWLIST_WRLOCK(&logchannels);
300         while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list)))
301                 ast_free(chan);
302         global_logmask = 0;
303         if (!locked)
304                 AST_RWLIST_UNLOCK(&logchannels);
305         
306         errno = 0;
307         /* close syslog */
308         closelog();
309         
310         /* If no config file, we're fine, set default options. */
311         if (!cfg) {
312                 if (errno)
313                         fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno));
314                 else
315                         fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n");
316                 if (!(chan = ast_calloc(1, sizeof(*chan))))
317                         return;
318                 chan->type = LOGTYPE_CONSOLE;
319                 chan->logmask = __LOG_WARNING | __LOG_NOTICE | __LOG_ERROR;
320                 if (!locked)
321                         AST_RWLIST_WRLOCK(&logchannels);
322                 AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
323                 global_logmask |= chan->logmask;
324                 if (!locked)
325                         AST_RWLIST_UNLOCK(&logchannels);
326                 return;
327         }
328         
329         if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
330                 if (ast_true(s)) {
331                         if (gethostname(hostname, sizeof(hostname) - 1)) {
332                                 ast_copy_string(hostname, "unknown", sizeof(hostname));
333                                 fprintf(stderr, "What box has no hostname???\n");
334                         }
335                 } else
336                         hostname[0] = '\0';
337         } else
338                 hostname[0] = '\0';
339         if ((s = ast_variable_retrieve(cfg, "general", "dateformat")))
340                 ast_copy_string(dateformat, s, sizeof(dateformat));
341         else
342                 ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
343         if ((s = ast_variable_retrieve(cfg, "general", "queue_log")))
344                 logfiles.queue_log = ast_true(s);
345         if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name")))
346                 ast_copy_string(queue_log_name, s, sizeof(queue_log_name));
347         if ((s = ast_variable_retrieve(cfg, "general", "exec_after_rotate")))
348                 ast_copy_string(exec_after_rotate, s, sizeof(exec_after_rotate));
349         if ((s = ast_variable_retrieve(cfg, "general", "rotatestrategy"))) {
350                 if (strcasecmp(s, "timestamp") == 0)
351                         rotatestrategy = TIMESTAMP;
352                 else if (strcasecmp(s, "rotate") == 0)
353                         rotatestrategy = ROTATE;
354                 else if (strcasecmp(s, "sequential") == 0)
355                         rotatestrategy = SEQUENTIAL;
356                 else
357                         fprintf(stderr, "Unknown rotatestrategy: %s\n", s);
358         } else {
359                 if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp"))) {
360                         rotatestrategy = ast_true(s) ? TIMESTAMP : SEQUENTIAL;
361                         fprintf(stderr, "rotatetimestamp option has been deprecated.  Please use rotatestrategy instead.\n");
362                 }
363         }
364
365         if (!locked)
366                 AST_RWLIST_WRLOCK(&logchannels);
367         var = ast_variable_browse(cfg, "logfiles");
368         for (; var; var = var->next) {
369                 if (!(chan = make_logchannel(var->name, var->value, var->lineno)))
370                         continue;
371                 AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
372                 global_logmask |= chan->logmask;
373         }
374         if (!locked)
375                 AST_RWLIST_UNLOCK(&logchannels);
376
377         ast_config_destroy(cfg);
378 }
379
380 void ast_child_verbose(int level, const char *fmt, ...)
381 {
382         char *msg = NULL, *emsg = NULL, *sptr, *eptr;
383         va_list ap, aq;
384         int size;
385
386         /* Don't bother, if the level isn't that high */
387         if (option_verbose < level) {
388                 return;
389         }
390
391         va_start(ap, fmt);
392         va_copy(aq, ap);
393         if ((size = vsnprintf(msg, 0, fmt, ap)) < 0) {
394                 va_end(ap);
395                 va_end(aq);
396                 return;
397         }
398         va_end(ap);
399
400         if (!(msg = ast_malloc(size + 1))) {
401                 va_end(aq);
402                 return;
403         }
404
405         vsnprintf(msg, size + 1, fmt, aq);
406         va_end(aq);
407
408         if (!(emsg = ast_malloc(size * 2 + 1))) {
409                 ast_free(msg);
410                 return;
411         }
412
413         for (sptr = msg, eptr = emsg; ; sptr++) {
414                 if (*sptr == '"') {
415                         *eptr++ = '\\';
416                 }
417                 *eptr++ = *sptr;
418                 if (*sptr == '\0') {
419                         break;
420                 }
421         }
422         ast_free(msg);
423
424         fprintf(stdout, "verbose \"%s\" %d\n", emsg, level);
425         fflush(stdout);
426         ast_free(emsg);
427 }
428
429 void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
430 {
431         va_list ap;
432         char qlog_msg[8192];
433         int qlog_len;
434         char time_str[16];
435
436         if (ast_check_realtime("queue_log")) {
437                 va_start(ap, fmt);
438                 vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap);
439                 va_end(ap);
440                 snprintf(time_str, sizeof(time_str), "%ld", (long)time(NULL));
441                 ast_store_realtime("queue_log", "time", time_str, 
442                                                 "callid", callid, 
443                                                 "queuename", queuename, 
444                                                 "agent", agent, 
445                                                 "event", event,
446                                                 "data", qlog_msg,
447                                                 SENTINEL);
448         } else {
449                 if (qlog) {
450                         va_start(ap, fmt);
451                         qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
452                         vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
453                         va_end(ap);
454                 }
455                 AST_RWLIST_RDLOCK(&logchannels);
456                 if (qlog) {
457                         fprintf(qlog, "%s\n", qlog_msg);
458                         fflush(qlog);
459                 }
460                 AST_RWLIST_UNLOCK(&logchannels);
461         }
462 }
463
464 static int rotate_file(const char *filename)
465 {
466         char old[PATH_MAX];
467         char new[PATH_MAX];
468         int x, y, which, found, res = 0, fd;
469         char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
470
471         switch (rotatestrategy) {
472         case SEQUENTIAL:
473                 for (x = 0; ; x++) {
474                         snprintf(new, sizeof(new), "%s.%d", filename, x);
475                         fd = open(new, O_RDONLY);
476                         if (fd > -1)
477                                 close(fd);
478                         else
479                                 break;
480                 }
481                 if (rename(filename, new)) {
482                         fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
483                         res = -1;
484                 }
485                 break;
486         case TIMESTAMP:
487                 snprintf(new, sizeof(new), "%s.%ld", filename, (long)time(NULL));
488                 if (rename(filename, new)) {
489                         fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
490                         res = -1;
491                 }
492                 break;
493         case ROTATE:
494                 /* Find the next empty slot, including a possible suffix */
495                 for (x = 0; ; x++) {
496                         found = 0;
497                         for (which = 0; which < ARRAY_LEN(suffixes); which++) {
498                                 snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]);
499                                 fd = open(new, O_RDONLY);
500                                 if (fd > -1) {
501                                         close(fd);
502                                         found = 1;
503                                         break;
504                                 }
505                         }
506                         if (!found) {
507                                 break;
508                         }
509                 }
510
511                 /* Found an empty slot */
512                 for (y = x; y > 0; y--) {
513                         for (which = 0; which < ARRAY_LEN(suffixes); which++) {
514                                 snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]);
515                                 fd = open(old, O_RDONLY);
516                                 if (fd > -1) {
517                                         /* Found the right suffix */
518                                         close(fd);
519                                         snprintf(new, sizeof(new), "%s.%d%s", filename, y, suffixes[which]);
520                                         if (rename(old, new)) {
521                                                 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
522                                                 res = -1;
523                                         }
524                                         break;
525                                 }
526                         }
527                 }
528
529                 /* Finally, rename the current file */
530                 snprintf(new, sizeof(new), "%s.0", filename);
531                 if (rename(filename, new)) {
532                         fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
533                         res = -1;
534                 }
535         }
536
537         if (!ast_strlen_zero(exec_after_rotate)) {
538                 struct ast_channel *c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Logger/rotate");
539                 char buf[512];
540                 pbx_builtin_setvar_helper(c, "filename", filename);
541                 pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf));
542                 if (ast_safe_system(buf) != -1) {
543                         ast_log(LOG_WARNING, "error executing '%s'\n", buf);
544                 }
545                 c = ast_channel_release(c);
546         }
547         return res;
548 }
549
550 static int reload_logger(int rotate)
551 {
552         char old[PATH_MAX] = "";
553         int queue_rotate = rotate;
554         struct logchannel *f;
555         int res = 0;
556         struct stat st;
557
558         AST_RWLIST_WRLOCK(&logchannels);
559
560         if (qlog) {
561                 if (rotate < 0) {
562                         /* Check filesize - this one typically doesn't need an auto-rotate */
563                         snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
564                         if (stat(old, &st) != 0 || st.st_size > 0x40000000) { /* Arbitrarily, 1 GB */
565                                 fclose(qlog);
566                                 qlog = NULL;
567                         } else
568                                 queue_rotate = 0;
569                 } else {
570                         fclose(qlog);
571                         qlog = NULL;
572                 }
573         } else 
574                 queue_rotate = 0;
575
576         ast_mkdir(ast_config_AST_LOG_DIR, 0777);
577
578         AST_RWLIST_TRAVERSE(&logchannels, f, list) {
579                 if (f->disabled) {
580                         f->disabled = 0;        /* Re-enable logging at reload */
581                         manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
582                 }
583                 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
584                         fclose(f->fileptr);     /* Close file */
585                         f->fileptr = NULL;
586                         if (rotate)
587                                 rotate_file(f->filename);
588                 }
589         }
590
591         filesize_reload_needed = 0;
592
593         init_logger_chain(1 /* locked */);
594
595         if (logfiles.queue_log) {
596                 snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
597                 if (queue_rotate)
598                         rotate_file(old);
599
600                 qlog = fopen(old, "a");
601                 if (qlog) {
602                         AST_RWLIST_UNLOCK(&logchannels);
603                         ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
604                         AST_RWLIST_WRLOCK(&logchannels);
605                         ast_verb(1, "Asterisk Queue Logger restarted\n");
606                 } else {
607                         ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
608                         res = -1;
609                 }
610         }
611
612         AST_RWLIST_UNLOCK(&logchannels);
613
614         return res;
615 }
616
617 /*! \brief Reload the logger module without rotating log files (also used from loader.c during
618         a full Asterisk reload) */
619 int logger_reload(void)
620 {
621         if(reload_logger(0))
622                 return RESULT_FAILURE;
623         return RESULT_SUCCESS;
624 }
625
626 static char *handle_logger_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
627 {
628         switch (cmd) {
629         case CLI_INIT:
630                 e->command = "logger reload";
631                 e->usage = 
632                         "Usage: logger reload\n"
633                         "       Reloads the logger subsystem state.  Use after restarting syslogd(8) if you are using syslog logging.\n";
634                 return NULL;
635         case CLI_GENERATE:
636                 return NULL;
637         }
638         if (reload_logger(0)) {
639                 ast_cli(a->fd, "Failed to reload the logger\n");
640                 return CLI_FAILURE;
641         }
642         return CLI_SUCCESS;
643 }
644
645 static char *handle_logger_rotate(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
646 {
647         switch (cmd) {
648         case CLI_INIT:
649                 e->command = "logger rotate";
650                 e->usage = 
651                         "Usage: logger rotate\n"
652                         "       Rotates and Reopens the log files.\n";
653                 return NULL;
654         case CLI_GENERATE:
655                 return NULL;    
656         }
657         if (reload_logger(1)) {
658                 ast_cli(a->fd, "Failed to reload the logger and rotate log files\n");
659                 return CLI_FAILURE;
660         } 
661         return CLI_SUCCESS;
662 }
663
664 static char *handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
665 {
666         int x;
667         int state;
668         int level = -1;
669
670         switch (cmd) {
671         case CLI_INIT:
672                 e->command = "logger set level";
673                 e->usage = 
674                         "Usage: logger set level\n"
675                         "       Set a specific log level to enabled/disabled for this console.\n";
676                 return NULL;
677         case CLI_GENERATE:
678                 return NULL;
679         }
680
681         if (a->argc < 5)
682                 return CLI_SHOWUSAGE;
683
684         AST_RWLIST_WRLOCK(&logchannels);
685
686         for (x = 0; x < ARRAY_LEN(levels); x++) {
687                 if (levels[x] && !strcasecmp(a->argv[3], levels[x])) {
688                         level = x;
689                         break;
690                 }
691         }
692
693         AST_RWLIST_UNLOCK(&logchannels);
694
695         state = ast_true(a->argv[4]) ? 1 : 0;
696
697         if (level != -1) {
698                 ast_console_toggle_loglevel(a->fd, level, state);
699                 ast_cli(a->fd, "Logger status for '%s' has been set to '%s'.\n", levels[level], state ? "on" : "off");
700         } else
701                 return CLI_SHOWUSAGE;
702
703         return CLI_SUCCESS;
704 }
705
706 /*! \brief CLI command to show logging system configuration */
707 static char *handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
708 {
709 #define FORMATL "%-35.35s %-8.8s %-9.9s "
710         struct logchannel *chan;
711         switch (cmd) {
712         case CLI_INIT:
713                 e->command = "logger show channels";
714                 e->usage = 
715                         "Usage: logger show channels\n"
716                         "       List configured logger channels.\n";
717                 return NULL;
718         case CLI_GENERATE:
719                 return NULL;    
720         }
721         ast_cli(a->fd, FORMATL, "Channel", "Type", "Status");
722         ast_cli(a->fd, "Configuration\n");
723         ast_cli(a->fd, FORMATL, "-------", "----", "------");
724         ast_cli(a->fd, "-------------\n");
725         AST_RWLIST_RDLOCK(&logchannels);
726         AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
727                 unsigned int level;
728
729                 ast_cli(a->fd, FORMATL, chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" : (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"),
730                         chan->disabled ? "Disabled" : "Enabled");
731                 ast_cli(a->fd, " - ");
732                 for (level = 0; level < ARRAY_LEN(levels); level++) {
733                         if (chan->logmask & (1 << level)) {
734                                 ast_cli(a->fd, "%s ", levels[level]);
735                         }
736                 }
737                 ast_cli(a->fd, "\n");
738         }
739         AST_RWLIST_UNLOCK(&logchannels);
740         ast_cli(a->fd, "\n");
741                 
742         return CLI_SUCCESS;
743 }
744
745 struct verb {
746         void (*verboser)(const char *string);
747         AST_LIST_ENTRY(verb) list;
748 };
749
750 static AST_RWLIST_HEAD_STATIC(verbosers, verb);
751
752 static struct ast_cli_entry cli_logger[] = {
753         AST_CLI_DEFINE(handle_logger_show_channels, "List configured log channels"),
754         AST_CLI_DEFINE(handle_logger_reload, "Reopens the log files"),
755         AST_CLI_DEFINE(handle_logger_rotate, "Rotates and reopens the log files"),
756         AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console")
757 };
758
759 static int handle_SIGXFSZ(int sig) 
760 {
761         /* Indicate need to reload */
762         filesize_reload_needed = 1;
763         return 0;
764 }
765
766 static void ast_log_vsyslog(struct logmsg *msg)
767 {
768         char buf[BUFSIZ];
769         int syslog_level = ast_syslog_priority_from_loglevel(msg->level);
770
771         if (syslog_level < 0) {
772                 /* we are locked here, so cannot ast_log() */
773                 fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", msg->level);
774                 return;
775         }
776
777         if (msg->level == __LOG_VERBOSE) {
778                 snprintf(buf, sizeof(buf), "VERBOSE[%ld]: %s", msg->process_id, msg->message);
779                 msg->level = __LOG_DEBUG;
780         } else if (msg->level == __LOG_DTMF) {
781                 snprintf(buf, sizeof(buf), "DTMF[%ld]: %s", msg->process_id, msg->message);
782                 msg->level = __LOG_DEBUG;
783         } else {
784                 snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: %s",
785                          levels[msg->level], msg->process_id, msg->file, msg->line, msg->function, msg->message);
786         }
787
788         term_strip(buf, buf, strlen(buf) + 1);
789         syslog(syslog_level, "%s", buf);
790 }
791
792 /*! \brief Print a normal log message to the channels */
793 static void logger_print_normal(struct logmsg *logmsg)
794 {
795         struct logchannel *chan = NULL;
796         char buf[BUFSIZ];
797
798         AST_RWLIST_RDLOCK(&logchannels);
799
800         if (!AST_RWLIST_EMPTY(&logchannels)) {
801                 AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
802                         /* If the channel is disabled, then move on to the next one */
803                         if (chan->disabled)
804                                 continue;
805                         /* Check syslog channels */
806                         if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << logmsg->level))) {
807                                 ast_log_vsyslog(logmsg);
808                         /* Console channels */
809                         } else if (chan->type == LOGTYPE_CONSOLE && (chan->logmask & (1 << logmsg->level))) {
810                                 char linestr[128];
811                                 char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
812
813                                 /* If the level is verbose, then skip it */
814                                 if (logmsg->level == __LOG_VERBOSE)
815                                         continue;
816
817                                 /* Turn the numerical line number into a string */
818                                 snprintf(linestr, sizeof(linestr), "%d", logmsg->line);
819                                 /* Build string to print out */
820                                 snprintf(buf, sizeof(buf), "[%s] %s[%ld]: %s:%s %s: %s",
821                                          logmsg->date,
822                                          term_color(tmp1, logmsg->level_name, colors[logmsg->level], 0, sizeof(tmp1)),
823                                          logmsg->process_id,
824                                          term_color(tmp2, logmsg->file, COLOR_BRWHITE, 0, sizeof(tmp2)),
825                                          term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
826                                          term_color(tmp4, logmsg->function, COLOR_BRWHITE, 0, sizeof(tmp4)),
827                                          logmsg->message);
828                                 /* Print out */
829                                 ast_console_puts_mutable(buf, logmsg->level);
830                         /* File channels */
831                         } else if (chan->type == LOGTYPE_FILE && (chan->logmask & (1 << logmsg->level))) {
832                                 int res = 0;
833
834                                 /* If no file pointer exists, skip it */
835                                 if (!chan->fileptr)
836                                         continue;
837                                 
838                                 /* Print out to the file */
839                                 res = fprintf(chan->fileptr, "[%s] %s[%ld] %s: %s",
840                                               logmsg->date, logmsg->level_name, logmsg->process_id, logmsg->file, logmsg->message);
841                                 if (res <= 0 && !ast_strlen_zero(logmsg->message)) {
842                                         fprintf(stderr, "**** Asterisk Logging Error: ***********\n");
843                                         if (errno == ENOMEM || errno == ENOSPC)
844                                                 fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
845                                         else
846                                                 fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
847                                         manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
848                                         chan->disabled = 1;
849                                 } else if (res > 0) {
850                                         fflush(chan->fileptr);
851                                 }
852                         }
853                 }
854         } else if (logmsg->level != __LOG_VERBOSE) {
855                 fputs(logmsg->message, stdout);
856         }
857
858         AST_RWLIST_UNLOCK(&logchannels);
859
860         /* If we need to reload because of the file size, then do so */
861         if (filesize_reload_needed) {
862                 reload_logger(-1);
863                 ast_verb(1, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
864         }
865
866         return;
867 }
868
869 /*! \brief Print a verbose message to the verbosers */
870 static void logger_print_verbose(struct logmsg *logmsg)
871 {
872         struct verb *v = NULL;
873
874         /* Iterate through the list of verbosers and pass them the log message string */
875         AST_RWLIST_RDLOCK(&verbosers);
876         AST_RWLIST_TRAVERSE(&verbosers, v, list)
877                 v->verboser(logmsg->message);
878         AST_RWLIST_UNLOCK(&verbosers);
879
880         return;
881 }
882
883 /*! \brief Actual logging thread */
884 static void *logger_thread(void *data)
885 {
886         struct logmsg *next = NULL, *msg = NULL;
887
888         for (;;) {
889                 /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
890                 AST_LIST_LOCK(&logmsgs);
891                 if (AST_LIST_EMPTY(&logmsgs)) {
892                         if (close_logger_thread) {
893                                 break;
894                         } else {
895                                 ast_cond_wait(&logcond, &logmsgs.lock);
896                         }
897                 }
898                 next = AST_LIST_FIRST(&logmsgs);
899                 AST_LIST_HEAD_INIT_NOLOCK(&logmsgs);
900                 AST_LIST_UNLOCK(&logmsgs);
901
902                 /* Otherwise go through and process each message in the order added */
903                 while ((msg = next)) {
904                         /* Get the next entry now so that we can free our current structure later */
905                         next = AST_LIST_NEXT(msg, list);
906
907                         /* Depending on the type, send it to the proper function */
908                         if (msg->type == LOGMSG_NORMAL)
909                                 logger_print_normal(msg);
910                         else if (msg->type == LOGMSG_VERBOSE)
911                                 logger_print_verbose(msg);
912
913                         /* Free the data since we are done */
914                         ast_free(msg);
915                 }
916
917                 /* If we should stop, then stop */
918                 if (close_logger_thread)
919                         break;
920         }
921
922         return NULL;
923 }
924
925 int init_logger(void)
926 {
927         char tmp[256];
928         int res = 0;
929
930         /* auto rotate if sig SIGXFSZ comes a-knockin */
931         (void) signal(SIGXFSZ, (void *) handle_SIGXFSZ);
932
933         /* start logger thread */
934         ast_cond_init(&logcond, NULL);
935         if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
936                 ast_cond_destroy(&logcond);
937                 return -1;
938         }
939
940         /* register the logger cli commands */
941         ast_cli_register_multiple(cli_logger, ARRAY_LEN(cli_logger));
942
943         ast_mkdir(ast_config_AST_LOG_DIR, 0777);
944   
945         /* create log channels */
946         init_logger_chain(0 /* locked */);
947
948         if (logfiles.queue_log) {
949                 snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
950                 qlog = fopen(tmp, "a");
951                 ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
952         }
953         return res;
954 }
955
956 void close_logger(void)
957 {
958         struct logchannel *f = NULL;
959
960         /* Stop logger thread */
961         AST_LIST_LOCK(&logmsgs);
962         close_logger_thread = 1;
963         ast_cond_signal(&logcond);
964         AST_LIST_UNLOCK(&logmsgs);
965
966         if (logthread != AST_PTHREADT_NULL)
967                 pthread_join(logthread, NULL);
968
969         AST_RWLIST_WRLOCK(&logchannels);
970
971         if (qlog) {
972                 fclose(qlog);
973                 qlog = NULL;
974         }
975
976         AST_RWLIST_TRAVERSE(&logchannels, f, list) {
977                 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
978                         fclose(f->fileptr);
979                         f->fileptr = NULL;
980                 }
981         }
982
983         closelog(); /* syslog */
984
985         AST_RWLIST_UNLOCK(&logchannels);
986
987         return;
988 }
989
990 /*!
991  * \brief send log messages to syslog and/or the console
992  */
993 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
994 {
995         struct logmsg *logmsg = NULL;
996         struct ast_str *buf = NULL;
997         struct ast_tm tm;
998         struct timeval now = ast_tvnow();
999         int res = 0;
1000         va_list ap;
1001         char datestring[256];
1002
1003         if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
1004                 return;
1005
1006         if (AST_RWLIST_EMPTY(&logchannels)) {
1007                 /*
1008                  * we don't have the logger chain configured yet,
1009                  * so just log to stdout
1010                  */
1011                 if (level != __LOG_VERBOSE) {
1012                         int result;
1013                         va_start(ap, fmt);
1014                         result = ast_str_set_va(&buf, BUFSIZ, fmt, ap); /* XXX BUFSIZ ? */
1015                         va_end(ap);
1016                         if (result != AST_DYNSTR_BUILD_FAILED) {
1017                                 term_filter_escapes(ast_str_buffer(buf));
1018                                 fputs(ast_str_buffer(buf), stdout);
1019                         }
1020                 }
1021                 return;
1022         }
1023         
1024         /* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
1025            are non-zero; LOG_DEBUG messages can still be displayed if option_debug
1026            is zero, if option_verbose is non-zero (this allows for 'level zero'
1027            LOG_DEBUG messages to be displayed, if the logmask on any channel
1028            allows it)
1029         */
1030         if (!option_verbose && !option_debug && (level == __LOG_DEBUG))
1031                 return;
1032
1033         /* Ignore anything that never gets logged anywhere */
1034         if (!(global_logmask & (1 << level)))
1035                 return;
1036         
1037         /* Build string */
1038         va_start(ap, fmt);
1039         res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
1040         va_end(ap);
1041
1042         /* If the build failed, then abort and free this structure */
1043         if (res == AST_DYNSTR_BUILD_FAILED)
1044                 return;
1045
1046         /* Create a new logging message */
1047         if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128)))
1048                 return;
1049
1050         /* Copy string over */
1051         ast_string_field_set(logmsg, message, ast_str_buffer(buf));
1052
1053         /* Set type to be normal */
1054         logmsg->type = LOGMSG_NORMAL;
1055
1056         /* Create our date/time */
1057         ast_localtime(&now, &tm, NULL);
1058         ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
1059         ast_string_field_set(logmsg, date, datestring);
1060
1061         /* Copy over data */
1062         logmsg->level = level;
1063         logmsg->line = line;
1064         ast_string_field_set(logmsg, level_name, levels[level]);
1065         ast_string_field_set(logmsg, file, file);
1066         ast_string_field_set(logmsg, function, function);
1067         logmsg->process_id = (long) GETTID();
1068
1069         /* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
1070         if (logthread != AST_PTHREADT_NULL) {
1071                 AST_LIST_LOCK(&logmsgs);
1072                 AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
1073                 ast_cond_signal(&logcond);
1074                 AST_LIST_UNLOCK(&logmsgs);
1075         } else {
1076                 logger_print_normal(logmsg);
1077                 ast_free(logmsg);
1078         }
1079
1080         return;
1081 }
1082
1083 #ifdef HAVE_BKTR
1084
1085 struct ast_bt *ast_bt_create(void) 
1086 {
1087         struct ast_bt *bt = ast_calloc(1, sizeof(*bt));
1088         if (!bt) {
1089                 ast_log(LOG_ERROR, "Unable to allocate memory for backtrace structure!\n");
1090                 return NULL;
1091         }
1092
1093         bt->alloced = 1;
1094
1095         ast_bt_get_addresses(bt);
1096
1097         return bt;
1098 }
1099
1100 int ast_bt_get_addresses(struct ast_bt *bt)
1101 {
1102         bt->num_frames = backtrace(bt->addresses, AST_MAX_BT_FRAMES);
1103
1104         return 0;
1105 }
1106
1107 void *ast_bt_destroy(struct ast_bt *bt)
1108 {
1109         if (bt->alloced) {
1110                 ast_free(bt);
1111         }
1112
1113         return NULL;
1114 }
1115
1116 #endif /* HAVE_BKTR */
1117
1118 void ast_backtrace(void)
1119 {
1120 #ifdef HAVE_BKTR
1121         struct ast_bt *bt;
1122         int i = 0;
1123         char **strings;
1124
1125         if (!(bt = ast_bt_create())) {
1126                 ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
1127                 return;
1128         }
1129
1130         if ((strings = backtrace_symbols(bt->addresses, bt->num_frames))) {
1131                 ast_debug(1, "Got %d backtrace record%c\n", bt->num_frames, bt->num_frames != 1 ? 's' : ' ');
1132                 for (i = 0; i < bt->num_frames; i++) {
1133                         ast_log(LOG_DEBUG, "#%d: [%p] %s\n", i, bt->addresses[i], strings[i]);
1134                 }
1135
1136                 /* MALLOC_DEBUG will erroneously report an error here, unless we undef the macro. */
1137 #undef free
1138                 free(strings);
1139         } else {
1140                 ast_debug(1, "Could not allocate memory for backtrace\n");
1141         }
1142         ast_bt_destroy(bt);
1143 #else
1144         ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
1145 #endif
1146 }
1147
1148 void __ast_verbose_ap(const char *file, int line, const char *func, const char *fmt, va_list ap)
1149 {
1150         struct logmsg *logmsg = NULL;
1151         struct ast_str *buf = NULL;
1152         int res = 0;
1153
1154         if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
1155                 return;
1156
1157         if (ast_opt_timestamp) {
1158                 struct timeval now;
1159                 struct ast_tm tm;
1160                 char date[40];
1161                 char *datefmt;
1162
1163                 now = ast_tvnow();
1164                 ast_localtime(&now, &tm, NULL);
1165                 ast_strftime(date, sizeof(date), dateformat, &tm);
1166                 datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
1167                 sprintf(datefmt, "%c[%s] %s", 127, date, fmt);
1168                 fmt = datefmt;
1169         } else {
1170                 char *tmp = alloca(strlen(fmt) + 2);
1171                 sprintf(tmp, "%c%s", 127, fmt);
1172                 fmt = tmp;
1173         }
1174
1175         /* Build string */
1176         res = ast_str_set_va(&buf, 0, fmt, ap);
1177
1178         /* If the build failed then we can drop this allocated message */
1179         if (res == AST_DYNSTR_BUILD_FAILED)
1180                 return;
1181
1182         if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128)))
1183                 return;
1184
1185         ast_string_field_set(logmsg, message, ast_str_buffer(buf));
1186
1187         ast_log(__LOG_VERBOSE, file, line, func, "%s", logmsg->message + 1);
1188
1189         /* Set type */
1190         logmsg->type = LOGMSG_VERBOSE;
1191         
1192         /* Add to the list and poke the thread if possible */
1193         if (logthread != AST_PTHREADT_NULL) {
1194                 AST_LIST_LOCK(&logmsgs);
1195                 AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
1196                 ast_cond_signal(&logcond);
1197                 AST_LIST_UNLOCK(&logmsgs);
1198         } else {
1199                 logger_print_verbose(logmsg);
1200                 ast_free(logmsg);
1201         }
1202 }
1203
1204 void __ast_verbose(const char *file, int line, const char *func, const char *fmt, ...)
1205 {
1206         va_list ap;
1207
1208         va_start(ap, fmt);
1209         __ast_verbose_ap(file, line, func, fmt, ap);
1210         va_end(ap);
1211 }
1212
1213 /* No new code should use this directly, but we have the ABI for backwards compat */
1214 #undef ast_verbose
1215 void __attribute__((format(printf, 1,2))) ast_verbose(const char *fmt, ...);
1216 void ast_verbose(const char *fmt, ...)
1217 {
1218         va_list ap;
1219
1220         va_start(ap, fmt);
1221         __ast_verbose_ap("", 0, "", fmt, ap);
1222         va_end(ap);
1223 }
1224
1225 int ast_register_verbose(void (*v)(const char *string)) 
1226 {
1227         struct verb *verb;
1228
1229         if (!(verb = ast_malloc(sizeof(*verb))))
1230                 return -1;
1231
1232         verb->verboser = v;
1233
1234         AST_RWLIST_WRLOCK(&verbosers);
1235         AST_RWLIST_INSERT_HEAD(&verbosers, verb, list);
1236         AST_RWLIST_UNLOCK(&verbosers);
1237         
1238         return 0;
1239 }
1240
1241 int ast_unregister_verbose(void (*v)(const char *string))
1242 {
1243         struct verb *cur;
1244
1245         AST_RWLIST_WRLOCK(&verbosers);
1246         AST_RWLIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
1247                 if (cur->verboser == v) {
1248                         AST_RWLIST_REMOVE_CURRENT(list);
1249                         ast_free(cur);
1250                         break;
1251                 }
1252         }
1253         AST_RWLIST_TRAVERSE_SAFE_END;
1254         AST_RWLIST_UNLOCK(&verbosers);
1255         
1256         return cur ? 0 : -1;
1257 }
1258
1259 static void update_logchannels(void)
1260 {
1261         struct logchannel *cur;
1262
1263         AST_RWLIST_WRLOCK(&logchannels);
1264
1265         global_logmask = 0;
1266
1267         AST_RWLIST_TRAVERSE(&logchannels, cur, list) {
1268                 cur->logmask = make_components(cur->components, cur->lineno);
1269                 global_logmask |= cur->logmask;
1270         }
1271
1272         AST_RWLIST_UNLOCK(&logchannels);
1273 }
1274
1275 int ast_logger_register_level(const char *name)
1276 {
1277         unsigned int level;
1278         unsigned int available = 0;
1279
1280         AST_RWLIST_WRLOCK(&logchannels);
1281
1282         for (level = 0; level < ARRAY_LEN(levels); level++) {
1283                 if ((level >= 16) && !available && !levels[level]) {
1284                         available = level;
1285                         continue;
1286                 }
1287
1288                 if (levels[level] && !strcasecmp(levels[level], name)) {
1289                         ast_log(LOG_WARNING,
1290                                 "Unable to register dynamic logger level '%s': a standard logger level uses that name.\n",
1291                                 name);
1292                         AST_RWLIST_UNLOCK(&logchannels);
1293
1294                         return -1;
1295                 }
1296         }
1297
1298         if (!available) {
1299                 ast_log(LOG_WARNING,
1300                         "Unable to register dynamic logger level '%s'; maximum number of levels registered.\n",
1301                         name);
1302                 AST_RWLIST_UNLOCK(&logchannels);
1303
1304                 return -1;
1305         }
1306
1307         levels[available] = ast_strdup(name);
1308
1309         AST_RWLIST_UNLOCK(&logchannels);
1310
1311         ast_debug(1, "Registered dynamic logger level '%s' with index %d.\n", name, available);
1312
1313         update_logchannels();
1314
1315         return available;
1316 }
1317
1318 void ast_logger_unregister_level(const char *name)
1319 {
1320         unsigned int found = 0;
1321         unsigned int x;
1322
1323         AST_RWLIST_WRLOCK(&logchannels);
1324
1325         for (x = 16; x < ARRAY_LEN(levels); x++) {
1326                 if (!levels[x]) {
1327                         continue;
1328                 }
1329
1330                 if (strcasecmp(levels[x], name)) {
1331                         continue;
1332                 }
1333
1334                 found = 1;
1335                 break;
1336         }
1337
1338         if (found) {
1339                 /* take this level out of the global_logmask, to ensure that no new log messages
1340                  * will be queued for it
1341                  */
1342
1343                 global_logmask &= ~(1 << x);
1344
1345                 free(levels[x]);
1346                 levels[x] = NULL;
1347                 AST_RWLIST_UNLOCK(&logchannels);
1348
1349                 ast_debug(1, "Unregistered dynamic logger level '%s' with index %d.\n", name, x);
1350
1351                 update_logchannels();
1352         } else {
1353                 AST_RWLIST_UNLOCK(&logchannels);
1354         }
1355 }
1356