aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-01-23 13:38:48 +0100
committerTobias Brunner <tobias@strongswan.org>2012-05-02 14:45:38 +0200
commitd724fcd6240b56359fede1ff6ecd7f0c576dbd0d (patch)
tree4c295a0e139239a59f8a02ac25ab2851a79dc87a /src/libcharon/plugins
parent4d21000cf71c9f89d81c1c54a0fc11be7a0c04b2 (diff)
downloadstrongswan-d724fcd6240b56359fede1ff6ecd7f0c576dbd0d.tar.bz2
strongswan-d724fcd6240b56359fede1ff6ecd7f0c576dbd0d.tar.xz
Ensure that multi-line log messages are not torn apart.
Diffstat (limited to 'src/libcharon/plugins')
-rw-r--r--src/libcharon/plugins/android/android_logger.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libcharon/plugins/android/android_logger.c b/src/libcharon/plugins/android/android_logger.c
index fbc2a93ce..845d3071e 100644
--- a/src/libcharon/plugins/android/android_logger.c
+++ b/src/libcharon/plugins/android/android_logger.c
@@ -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),
);