diff options
author | Martin Willi <martin@revosec.ch> | 2012-07-13 15:42:14 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-07-13 15:43:04 +0200 |
commit | d19f0ae3e0a6bbff549911e910c06d8ef51ad563 (patch) | |
tree | 63d2f3ee37b5b436541effe3f066f4f1a5393512 /src/libcharon/bus/listeners | |
parent | e0bfc4d63ceabeaef3f1d51191196198c8265e65 (diff) | |
download | strongswan-d19f0ae3e0a6bbff549911e910c06d8ef51ad563.tar.bz2 strongswan-d19f0ae3e0a6bbff549911e910c06d8ef51ad563.tar.xz |
Don't modify the message string passed to logger, as it gets reused
Diffstat (limited to 'src/libcharon/bus/listeners')
-rw-r--r-- | src/libcharon/bus/listeners/file_logger.c | 26 | ||||
-rw-r--r-- | src/libcharon/bus/listeners/logger.h | 2 | ||||
-rw-r--r-- | src/libcharon/bus/listeners/sys_logger.c | 18 |
3 files changed, 25 insertions, 21 deletions
diff --git a/src/libcharon/bus/listeners/file_logger.c b/src/libcharon/bus/listeners/file_logger.c index 77af9e4ed..9c8458eb5 100644 --- a/src/libcharon/bus/listeners/file_logger.c +++ b/src/libcharon/bus/listeners/file_logger.c @@ -62,10 +62,10 @@ struct private_file_logger_t { METHOD(logger_t, log_, void, private_file_logger_t *this, debug_t group, level_t level, int thread, - ike_sa_t* ike_sa, char *message) + ike_sa_t* ike_sa, const char *message) { char timestr[128], namestr[128] = ""; - char *current = message, *next; + const char *current = message, *next; struct tm tm; time_t t; @@ -95,24 +95,26 @@ METHOD(logger_t, log_, void, /* prepend a prefix in front of every line */ this->mutex->lock(this->mutex); - while (current) + while (TRUE) { next = strchr(current, '\n'); - if (next) - { - *(next++) = '\0'; - } if (this->time_format) { - fprintf(this->out, "%s %.2d[%N]%s %s\n", - timestr, thread, debug_names, group, namestr, current); + fprintf(this->out, "%s %.2d[%N]%s ", + timestr, thread, debug_names, group, namestr); } else { - fprintf(this->out, "%.2d[%N]%s %s\n", - thread, debug_names, group, namestr, current); + fprintf(this->out, "%.2d[%N]%s ", + thread, debug_names, group, namestr); + } + if (next == NULL) + { + fprintf(this->out, "%s\n", current); + break; } - current = next; + fprintf(this->out, "%.*s\n", (int)(next - current), current); + current = next + 1; } this->mutex->unlock(this->mutex); } diff --git a/src/libcharon/bus/listeners/logger.h b/src/libcharon/bus/listeners/logger.h index 030653635..3b99e7dc1 100644 --- a/src/libcharon/bus/listeners/logger.h +++ b/src/libcharon/bus/listeners/logger.h @@ -45,7 +45,7 @@ struct logger_t { * @param message log message */ void (*log)(logger_t *this, debug_t group, level_t level, int thread, - ike_sa_t *ike_sa, char* message); + ike_sa_t *ike_sa, const char *message); /** * Get the desired log level for a debug group. This is called during diff --git a/src/libcharon/bus/listeners/sys_logger.c b/src/libcharon/bus/listeners/sys_logger.c index 9962fe0f6..53fdefe89 100644 --- a/src/libcharon/bus/listeners/sys_logger.c +++ b/src/libcharon/bus/listeners/sys_logger.c @@ -57,10 +57,10 @@ struct private_sys_logger_t { METHOD(logger_t, log_, void, private_sys_logger_t *this, debug_t group, level_t level, int thread, - ike_sa_t* ike_sa, char *message) + ike_sa_t* ike_sa, const char *message) { char groupstr[4], namestr[128] = ""; - char *current = message, *next; + const char *current = message, *next; /* cache group name and optional name string */ snprintf(groupstr, sizeof(groupstr), "%N", debug_names, group); @@ -81,16 +81,18 @@ METHOD(logger_t, log_, void, /* do a syslog for every line */ this->mutex->lock(this->mutex); - while (current) + while (TRUE) { next = strchr(current, '\n'); - if (next) + if (next == NULL) { - *(next++) = '\0'; + syslog(this->facility | LOG_INFO, "%.2d[%s]%s %s\n", + thread, groupstr, namestr, current); + break; } - syslog(this->facility|LOG_INFO, "%.2d[%s]%s %s\n", - thread, groupstr, namestr, current); - current = next; + syslog(this->facility | LOG_INFO, "%.2d[%s]%s %.*s\n", + thread, groupstr, namestr, (int)(next - current), current); + current = next + 1; } this->mutex->unlock(this->mutex); } |