From 44d4ab7a960cf143c43d1645f2985cc9d74e3077 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Wed, 7 Apr 2010 11:00:36 +0200 Subject: Configurable syslog name. Also fixes a bug in syslog initialization. --- sysdep/unix/log.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'sysdep/unix/log.c') diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index 3d3b433..d4c3648 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -28,9 +28,9 @@ #include "lib/lists.h" #include "lib/unix.h" -static FILE *dbgf = NULL; +static FILE *dbgf; static list *current_log_list; -static list init_log_list; +static char *current_syslog_name; /* NULL -> syslog closed */ bird_clock_t rate_limit_time = 5; int rate_limit_count = 5; @@ -209,38 +209,55 @@ debug(char *msg, ...) va_end(args); } -void -log_init(int debug, int init) +static list * +default_log_list(int debug, int init, char **syslog_name) { - static struct log_config lc_stderr = { mask: ~0, terminal_flag: 1 }; - + static list init_log_list; init_list(&init_log_list); - current_log_list = &init_log_list; + *syslog_name = NULL; #ifdef HAVE_SYSLOG if (!debug) { static struct log_config lc_syslog = { mask: ~0 }; - openlog("bird", LOG_CONS | LOG_NDELAY, LOG_DAEMON); - add_tail(current_log_list, &lc_syslog.n); + add_tail(&init_log_list, &lc_syslog.n); + *syslog_name = bird_name; if (!init) - return; + return &init_log_list; } #endif + static struct log_config lc_stderr = { mask: ~0, terminal_flag: 1 }; lc_stderr.fh = stderr; - add_tail(current_log_list, &lc_stderr.n); + add_tail(&init_log_list, &lc_stderr.n); + return &init_log_list; } void -log_switch(int debug, list *l) +log_switch(int debug, list *l, char *new_syslog_name) { - if (EMPTY_LIST(*l)) - log_init(debug, 0); - else - current_log_list = l; + if (!l || EMPTY_LIST(*l)) + l = default_log_list(debug, !l, &new_syslog_name); + + current_log_list = l; + +#ifdef HAVE_SYSLOG + if (current_syslog_name && new_syslog_name && + !strcmp(current_syslog_name, new_syslog_name)) + return; + + if (current_syslog_name) + closelog(); + + if (new_syslog_name) + openlog(new_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON); + + current_syslog_name = new_syslog_name; +#endif } + + void log_init_debug(char *f) { -- cgit v1.2.3