summaryrefslogtreecommitdiff
path: root/sysdep/unix/log.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2010-04-07 11:00:36 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2010-04-07 15:34:45 +0200
commit44d4ab7a960cf143c43d1645f2985cc9d74e3077 (patch)
tree6fb7e65191951bce4d92c7b93d3a76dcf1fd9b6d /sysdep/unix/log.c
parentb8113a5e92cb19a0910041d5708f4eafeb713b54 (diff)
Configurable syslog name.
Also fixes a bug in syslog initialization.
Diffstat (limited to 'sysdep/unix/log.c')
-rw-r--r--sysdep/unix/log.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 3d3b4337..d4c36488 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)
{