mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-15 00:00:16 -04:00
Ensure that multi-line log messages are not torn apart.
This commit is contained in:
parent
4d21000cf7
commit
d724fcd624
@ -20,6 +20,7 @@
|
||||
|
||||
#include "file_logger.h"
|
||||
|
||||
#include <threading/mutex.h>
|
||||
|
||||
typedef struct private_file_logger_t private_file_logger_t;
|
||||
|
||||
@ -52,6 +53,11 @@ struct private_file_logger_t {
|
||||
* Print the name/# of the IKE_SA?
|
||||
*/
|
||||
bool ike_name;
|
||||
|
||||
/**
|
||||
* Mutex to ensure multi-line log messages are not torn apart
|
||||
*/
|
||||
mutex_t *mutex;
|
||||
};
|
||||
|
||||
METHOD(logger_t, log_, void,
|
||||
@ -93,6 +99,7 @@ METHOD(logger_t, log_, void,
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
|
||||
/* prepend a prefix in front of every line */
|
||||
this->mutex->lock(this->mutex);
|
||||
while (current)
|
||||
{
|
||||
next = strchr(current, '\n');
|
||||
@ -112,6 +119,7 @@ METHOD(logger_t, log_, void,
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +146,7 @@ METHOD(file_logger_t, destroy, void,
|
||||
{
|
||||
fclose(this->out);
|
||||
}
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -159,6 +168,7 @@ file_logger_t *file_logger_create(FILE *out, char *time_format, bool ike_name)
|
||||
.out = out,
|
||||
.time_format = time_format,
|
||||
.ike_name = ike_name,
|
||||
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||
);
|
||||
|
||||
set_level(this, DBG_ANY, LEVEL_SILENT);
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "sys_logger.h"
|
||||
|
||||
#include <threading/mutex.h>
|
||||
|
||||
typedef struct private_sys_logger_t private_sys_logger_t;
|
||||
|
||||
@ -47,6 +48,11 @@ struct private_sys_logger_t {
|
||||
* Print the name/# of the IKE_SA?
|
||||
*/
|
||||
bool ike_name;
|
||||
|
||||
/**
|
||||
* Mutex to ensure multi-line log messages are not torn apart
|
||||
*/
|
||||
mutex_t *mutex;
|
||||
};
|
||||
|
||||
METHOD(logger_t, log_, void,
|
||||
@ -78,6 +84,7 @@ METHOD(logger_t, log_, void,
|
||||
}
|
||||
|
||||
/* do a syslog for every line */
|
||||
this->mutex->lock(this->mutex);
|
||||
while (current)
|
||||
{
|
||||
next = strchr(current, '\n');
|
||||
@ -89,6 +96,7 @@ METHOD(logger_t, log_, void,
|
||||
thread, groupstr, namestr, current);
|
||||
current = next;
|
||||
}
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,6 +120,7 @@ METHOD(sys_logger_t, destroy, void,
|
||||
private_sys_logger_t *this)
|
||||
{
|
||||
closelog();
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -132,6 +141,7 @@ sys_logger_t *sys_logger_create(int facility, bool ike_name)
|
||||
},
|
||||
.facility = facility,
|
||||
.ike_name = ike_name,
|
||||
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||
);
|
||||
|
||||
set_level(this, DBG_ANY, LEVEL_SILENT);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Tobias Brunner
|
||||
* Copyright (C) 2010-2012 Tobias Brunner
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@ -20,6 +20,7 @@
|
||||
|
||||
#include <library.h>
|
||||
#include <daemon.h>
|
||||
#include <threading/mutex.h>
|
||||
|
||||
typedef struct private_android_logger_t private_android_logger_t;
|
||||
|
||||
@ -38,6 +39,10 @@ struct private_android_logger_t {
|
||||
*/
|
||||
int level;
|
||||
|
||||
/**
|
||||
* Mutex to ensure multi-line log messages are not torn apart
|
||||
*/
|
||||
mutex_t *mutex;
|
||||
};
|
||||
|
||||
|
||||
@ -52,6 +57,7 @@ METHOD(logger_t, log_, void,
|
||||
char *current = buffer, *next;
|
||||
snprintf(sgroup, sizeof(sgroup), "%N", debug_names, group);
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
this->mutex->lock(this->mutex);
|
||||
while (current)
|
||||
{ /* log each line separately */
|
||||
next = strchr(current, '\n');
|
||||
@ -63,12 +69,14 @@ METHOD(logger_t, log_, void,
|
||||
thread, sgroup, current);
|
||||
current = next;
|
||||
}
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(android_logger_t, destroy, void,
|
||||
private_android_logger_t *this)
|
||||
{
|
||||
this->mutex->destroy(this->mutex);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -86,6 +94,7 @@ android_logger_t *android_logger_create()
|
||||
},
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||
.level = lib->settings->get_int(lib->settings,
|
||||
"charon.plugins.android.loglevel", 1),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user