aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-01-21 14:47:13 +0100
committerTobias Brunner <tobias@strongswan.org>2012-05-02 14:45:38 +0200
commit0e474f9148deebcd3a24205f0110c884c9b67f60 (patch)
tree4a2ca8ac168f696e24d8fd988bb7b0e435d75299 /src/libcharon/plugins
parentf9f867899ae5f7198d2c80bf2519e542556095ba (diff)
downloadstrongswan-0e474f9148deebcd3a24205f0110c884c9b67f60.tar.bz2
strongswan-0e474f9148deebcd3a24205f0110c884c9b67f60.tar.xz
Use a separate interface for loggers.
The new interface does not allow loggers to unregister themselves from the bus. This allows us to use a rwlock_t for them. The latter also means that loggers can now be called concurrently by multiple threads.
Diffstat (limited to 'src/libcharon/plugins')
-rw-r--r--src/libcharon/plugins/android/android_logger.c6
-rw-r--r--src/libcharon/plugins/android/android_logger.h4
-rw-r--r--src/libcharon/plugins/android/android_plugin.c4
-rw-r--r--src/libcharon/plugins/sql/sql_logger.c20
-rw-r--r--src/libcharon/plugins/sql/sql_logger.h4
-rw-r--r--src/libcharon/plugins/sql/sql_plugin.c4
6 files changed, 20 insertions, 22 deletions
diff --git a/src/libcharon/plugins/android/android_logger.c b/src/libcharon/plugins/android/android_logger.c
index f7624b2c7..fbc2a93ce 100644
--- a/src/libcharon/plugins/android/android_logger.c
+++ b/src/libcharon/plugins/android/android_logger.c
@@ -41,7 +41,7 @@ struct private_android_logger_t {
};
-METHOD(listener_t, log_, bool,
+METHOD(logger_t, log_, void,
private_android_logger_t *this, debug_t group, level_t level,
int thread, ike_sa_t* ike_sa, char *format, va_list args)
{
@@ -64,8 +64,6 @@ METHOD(listener_t, log_, bool,
current = next;
}
}
- /* always stay registered */
- return TRUE;
}
METHOD(android_logger_t, destroy, void,
@@ -83,7 +81,7 @@ android_logger_t *android_logger_create()
INIT(this,
.public = {
- .listener = {
+ .logger = {
.log = _log_,
},
.destroy = _destroy,
diff --git a/src/libcharon/plugins/android/android_logger.h b/src/libcharon/plugins/android/android_logger.h
index c6fe5aff3..15abbb43f 100644
--- a/src/libcharon/plugins/android/android_logger.h
+++ b/src/libcharon/plugins/android/android_logger.h
@@ -31,9 +31,9 @@ typedef struct android_logger_t android_logger_t;
struct android_logger_t {
/**
- * Implements bus_listener_t interface
+ * Implements logger_t interface
*/
- listener_t listener;
+ logger_t logger;
/**
* Destroy the logger.
diff --git a/src/libcharon/plugins/android/android_plugin.c b/src/libcharon/plugins/android/android_plugin.c
index 091f34a8e..bad8bc042 100644
--- a/src/libcharon/plugins/android/android_plugin.c
+++ b/src/libcharon/plugins/android/android_plugin.c
@@ -68,7 +68,7 @@ METHOD(plugin_t, destroy, void,
hydra->attributes->remove_handler(hydra->attributes,
&this->handler->handler);
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
- charon->bus->remove_listener(charon->bus, &this->logger->listener);
+ charon->bus->remove_logger(charon->bus, &this->logger->logger);
this->creds->destroy(this->creds);
this->handler->destroy(this->handler);
this->logger->destroy(this->logger);
@@ -98,7 +98,7 @@ plugin_t *android_plugin_create()
this->service = android_service_create(this->creds);
this->handler = android_handler_create(this->service != NULL);
- charon->bus->add_listener(charon->bus, &this->logger->listener);
+ charon->bus->add_logger(charon->bus, &this->logger->logger);
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
diff --git a/src/libcharon/plugins/sql/sql_logger.c b/src/libcharon/plugins/sql/sql_logger.c
index 10ceacb00..e693bac48 100644
--- a/src/libcharon/plugins/sql/sql_logger.c
+++ b/src/libcharon/plugins/sql/sql_logger.c
@@ -18,6 +18,7 @@
#include "sql_logger.h"
#include <daemon.h>
+#include <threading/thread_value.h>
typedef struct private_sql_logger_t private_sql_logger_t;
@@ -42,20 +43,20 @@ struct private_sql_logger_t {
int level;
/**
- * avoid recursive logging
+ * avoid recursive calls by the same thread
*/
- bool recursive;
+ thread_value_t *recursive;
};
-METHOD(listener_t, log_, bool,
+METHOD(logger_t, log_, void,
private_sql_logger_t *this, debug_t group, level_t level, int thread,
ike_sa_t* ike_sa, char *format, va_list args)
{
- if (this->recursive)
+ if (this->recursive->get(this->recursive))
{
- return TRUE;
+ return;
}
- this->recursive = TRUE;
+ this->recursive->set(this->recursive, this->recursive);
if (ike_sa && level <= this->level)
{
@@ -108,9 +109,7 @@ METHOD(listener_t, log_, bool,
DB_BLOB, local_spi, DB_INT, group, DB_INT, level,
DB_TEXT, buffer);
}
- this->recursive = FALSE;
- /* always stay registered */
- return TRUE;
+ this->recursive->set(this->recursive, NULL);
}
METHOD(sql_logger_t, destroy, void,
@@ -128,12 +127,13 @@ sql_logger_t *sql_logger_create(database_t *db)
INIT(this,
.public = {
- .listener = {
+ .logger = {
.log = _log_,
},
.destroy = _destroy,
},
.db = db,
+ .recursive = thread_value_create(NULL),
.level = lib->settings->get_int(lib->settings,
"charon.plugins.sql.loglevel", -1),
);
diff --git a/src/libcharon/plugins/sql/sql_logger.h b/src/libcharon/plugins/sql/sql_logger.h
index a933705da..62dc3f361 100644
--- a/src/libcharon/plugins/sql/sql_logger.h
+++ b/src/libcharon/plugins/sql/sql_logger.h
@@ -32,9 +32,9 @@ typedef struct sql_logger_t sql_logger_t;
struct sql_logger_t {
/**
- * Implements bus_listener_t interface
+ * Implements logger_t interface
*/
- listener_t listener;
+ logger_t logger;
/**
* Destry the backend.
diff --git a/src/libcharon/plugins/sql/sql_plugin.c b/src/libcharon/plugins/sql/sql_plugin.c
index d915d4696..fc05fa547 100644
--- a/src/libcharon/plugins/sql/sql_plugin.c
+++ b/src/libcharon/plugins/sql/sql_plugin.c
@@ -64,7 +64,7 @@ METHOD(plugin_t, destroy, void,
{
charon->backends->remove_backend(charon->backends, &this->config->backend);
lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
- charon->bus->remove_listener(charon->bus, &this->logger->listener);
+ charon->bus->remove_logger(charon->bus, &this->logger->logger);
this->config->destroy(this->config);
this->cred->destroy(this->cred);
this->logger->destroy(this->logger);
@@ -110,7 +110,7 @@ plugin_t *sql_plugin_create()
charon->backends->add_backend(charon->backends, &this->config->backend);
lib->credmgr->add_set(lib->credmgr, &this->cred->set);
- charon->bus->add_listener(charon->bus, &this->logger->listener);
+ charon->bus->add_logger(charon->bus, &this->logger->logger);
return &this->public.plugin;
}