diff options
-rw-r--r-- | lib/string.h | 9 | ||||
-rw-r--r-- | sysdep/unix/log.c | 18 |
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/string.h b/lib/string.h index 9af49b9e..bf0b7cb0 100644 --- a/lib/string.h +++ b/lib/string.h @@ -30,6 +30,15 @@ static inline char *xbasename(const char *str) return s ? s+1 : (char *) str; } +static inline char * +xstrdup(const char *c) +{ + size_t l = strlen(c) + 1; + char *z = xmalloc(l); + memcpy(z, c, l); + return z; +} + #define ROUTER_ID_64_LENGTH 23 #endif diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index 1fd64426..b89e6b7a 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -288,18 +288,22 @@ log_switch(int debug, list *l, char *new_syslog_name) current_log_list = l; #ifdef HAVE_SYSLOG - char *old_syslog_name = current_syslog_name; - current_syslog_name = new_syslog_name; - - if (old_syslog_name && new_syslog_name && - !strcmp(old_syslog_name, new_syslog_name)) + if (current_syslog_name && new_syslog_name && + !strcmp(current_syslog_name, new_syslog_name)) return; - if (old_syslog_name) + if (current_syslog_name) + { closelog(); + xfree(current_syslog_name); + current_syslog_name = NULL; + } if (new_syslog_name) - openlog(new_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON); + { + current_syslog_name = xstrdup(new_syslog_name); + openlog(current_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON); + } #endif } |