Don't modify the message string passed to logger, as it gets reused
This commit is contained in:
@@ -62,10 +62,10 @@ struct private_file_logger_t {
|
|||||||
|
|
||||||
METHOD(logger_t, log_, void,
|
METHOD(logger_t, log_, void,
|
||||||
private_file_logger_t *this, debug_t group, level_t level, int thread,
|
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 timestr[128], namestr[128] = "";
|
||||||
char *current = message, *next;
|
const char *current = message, *next;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
@@ -95,24 +95,26 @@ METHOD(logger_t, log_, void,
|
|||||||
|
|
||||||
/* prepend a prefix in front of every line */
|
/* prepend a prefix in front of every line */
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
while (current)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
next = strchr(current, '\n');
|
next = strchr(current, '\n');
|
||||||
if (next)
|
|
||||||
{
|
|
||||||
*(next++) = '\0';
|
|
||||||
}
|
|
||||||
if (this->time_format)
|
if (this->time_format)
|
||||||
{
|
{
|
||||||
fprintf(this->out, "%s %.2d[%N]%s %s\n",
|
fprintf(this->out, "%s %.2d[%N]%s ",
|
||||||
timestr, thread, debug_names, group, namestr, current);
|
timestr, thread, debug_names, group, namestr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(this->out, "%.2d[%N]%s %s\n",
|
fprintf(this->out, "%.2d[%N]%s ",
|
||||||
thread, debug_names, group, namestr, current);
|
thread, debug_names, group, namestr);
|
||||||
}
|
}
|
||||||
current = next;
|
if (next == NULL)
|
||||||
|
{
|
||||||
|
fprintf(this->out, "%s\n", current);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(this->out, "%.*s\n", (int)(next - current), current);
|
||||||
|
current = next + 1;
|
||||||
}
|
}
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct logger_t {
|
|||||||
* @param message log message
|
* @param message log message
|
||||||
*/
|
*/
|
||||||
void (*log)(logger_t *this, debug_t group, level_t level, int thread,
|
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
|
* Get the desired log level for a debug group. This is called during
|
||||||
|
|||||||
@@ -57,10 +57,10 @@ struct private_sys_logger_t {
|
|||||||
|
|
||||||
METHOD(logger_t, log_, void,
|
METHOD(logger_t, log_, void,
|
||||||
private_sys_logger_t *this, debug_t group, level_t level, int thread,
|
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 groupstr[4], namestr[128] = "";
|
||||||
char *current = message, *next;
|
const char *current = message, *next;
|
||||||
|
|
||||||
/* cache group name and optional name string */
|
/* cache group name and optional name string */
|
||||||
snprintf(groupstr, sizeof(groupstr), "%N", debug_names, group);
|
snprintf(groupstr, sizeof(groupstr), "%N", debug_names, group);
|
||||||
@@ -81,16 +81,18 @@ METHOD(logger_t, log_, void,
|
|||||||
|
|
||||||
/* do a syslog for every line */
|
/* do a syslog for every line */
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
while (current)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
next = strchr(current, '\n');
|
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",
|
syslog(this->facility | LOG_INFO, "%.2d[%s]%s %.*s\n",
|
||||||
thread, groupstr, namestr, current);
|
thread, groupstr, namestr, (int)(next - current), current);
|
||||||
current = next;
|
current = next + 1;
|
||||||
}
|
}
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ static bool wait_for_listener(interface_job_t *job, u_int timeout)
|
|||||||
|
|
||||||
METHOD(logger_t, listener_log, void,
|
METHOD(logger_t, listener_log, void,
|
||||||
interface_logger_t *this, debug_t group, level_t level, int thread,
|
interface_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)
|
||||||
{
|
{
|
||||||
ike_sa_t *target;
|
ike_sa_t *target;
|
||||||
|
|
||||||
@@ -627,7 +627,7 @@ METHOD(controller_t, terminate_child, status_t,
|
|||||||
* See header
|
* See header
|
||||||
*/
|
*/
|
||||||
bool controller_cb_empty(void *param, debug_t group, level_t level,
|
bool controller_cb_empty(void *param, debug_t group, level_t level,
|
||||||
ike_sa_t *ike_sa, char *message)
|
ike_sa_t *ike_sa, const char *message)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
* @return FALSE to return from called controller method
|
* @return FALSE to return from called controller method
|
||||||
*/
|
*/
|
||||||
typedef bool (*controller_cb_t)(void* param, debug_t group, level_t level,
|
typedef bool (*controller_cb_t)(void* param, debug_t group, level_t level,
|
||||||
ike_sa_t* ike_sa, char* message);
|
ike_sa_t* ike_sa, const char *message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty callback function for controller_t methods.
|
* Empty callback function for controller_t methods.
|
||||||
@@ -43,7 +43,7 @@ typedef bool (*controller_cb_t)(void* param, debug_t group, level_t level,
|
|||||||
* this function to the controller methods.
|
* this function to the controller methods.
|
||||||
*/
|
*/
|
||||||
bool controller_cb_empty(void *param, debug_t group, level_t level,
|
bool controller_cb_empty(void *param, debug_t group, level_t level,
|
||||||
ike_sa_t *ike_sa, char *message);
|
ike_sa_t *ike_sa, const char *message);
|
||||||
|
|
||||||
typedef struct controller_t controller_t;
|
typedef struct controller_t controller_t;
|
||||||
|
|
||||||
|
|||||||
@@ -45,26 +45,27 @@ struct private_android_logger_t {
|
|||||||
mutex_t *mutex;
|
mutex_t *mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
METHOD(logger_t, log_, void,
|
METHOD(logger_t, log_, void,
|
||||||
private_android_logger_t *this, debug_t group, level_t level,
|
private_android_logger_t *this, debug_t group, level_t level,
|
||||||
int thread, ike_sa_t* ike_sa, char *message)
|
int thread, ike_sa_t* ike_sa, const char *message)
|
||||||
{
|
{
|
||||||
int prio = level > 1 ? ANDROID_LOG_DEBUG : ANDROID_LOG_INFO;
|
int prio = level > 1 ? ANDROID_LOG_DEBUG : ANDROID_LOG_INFO;
|
||||||
char sgroup[16];
|
char sgroup[16];
|
||||||
char *current = message, *next;
|
const char *current = message, *next;
|
||||||
snprintf(sgroup, sizeof(sgroup), "%N", debug_names, group);
|
snprintf(sgroup, sizeof(sgroup), "%N", debug_names, group);
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
while (current)
|
while (TRUE)
|
||||||
{ /* log each line separately */
|
{ /* log each line separately */
|
||||||
next = strchr(current, '\n');
|
next = strchr(current, '\n');
|
||||||
if (next)
|
if (next == NULL)
|
||||||
{
|
{
|
||||||
*(next++) = '\0';
|
__android_log_print(prio, "charon", "%.2d[%s] %s\n",
|
||||||
|
thread, sgroup, current);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
__android_log_print(prio, "charon", "%.2d[%s] %s\n",
|
__android_log_print(prio, "charon", "%.2d[%s] %.*s\n",
|
||||||
thread, sgroup, current);
|
thread, sgroup, (int)(next - current), current);
|
||||||
current = next;
|
current = next + 1;
|
||||||
}
|
}
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ struct private_sql_logger_t {
|
|||||||
|
|
||||||
METHOD(logger_t, log_, void,
|
METHOD(logger_t, log_, void,
|
||||||
private_sql_logger_t *this, debug_t group, level_t level, int thread,
|
private_sql_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)
|
||||||
{
|
{
|
||||||
if (this->recursive->get(this->recursive))
|
if (this->recursive->get(this->recursive))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user