aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-05-01 10:57:38 +0200
committerMartin Willi <martin@revosec.ch>2014-05-07 14:13:38 +0200
commit374511c52cb19bd8eb187c2f2aba2c86f396cb95 (patch)
tree60e748ce4b9af1caf5ea3565c504bff1a952a94e /src/libcharon/plugins
parent65cc8f55813a008d587a4d9210aa48c27616673b (diff)
downloadstrongswan-374511c52cb19bd8eb187c2f2aba2c86f396cb95.tar.bz2
strongswan-374511c52cb19bd8eb187c2f2aba2c86f396cb95.tar.xz
vici: Ensure we have no active users before mangling event client registrations
Diffstat (limited to 'src/libcharon/plugins')
-rw-r--r--src/libcharon/plugins/vici/vici_dispatcher.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/libcharon/plugins/vici/vici_dispatcher.c b/src/libcharon/plugins/vici/vici_dispatcher.c
index 0df867ad8..6db36fbe0 100644
--- a/src/libcharon/plugins/vici/vici_dispatcher.c
+++ b/src/libcharon/plugins/vici/vici_dispatcher.c
@@ -129,10 +129,19 @@ static void register_event(private_vici_dispatcher_t *this, char *name,
event_t *event;
this->mutex->lock(this->mutex);
- event = this->events->get(this->events, name);
- if (event)
+ while (TRUE)
{
- array_insert(event->clients, ARRAY_TAIL, &id);
+ event = this->events->get(this->events, name);
+ if (!event)
+ {
+ break;
+ }
+ if (!event->uses)
+ {
+ array_insert(event->clients, ARRAY_TAIL, &id);
+ break;
+ }
+ this->cond->wait(this->cond, this->mutex);
}
this->mutex->unlock(this->mutex);
@@ -160,20 +169,29 @@ static void unregister_event(private_vici_dispatcher_t *this, char *name,
bool found = FALSE;
this->mutex->lock(this->mutex);
- event = this->events->get(this->events, name);
- if (event)
+ while (TRUE)
{
- enumerator = array_create_enumerator(event->clients);
- while (enumerator->enumerate(enumerator, &current))
+ event = this->events->get(this->events, name);
+ if (!event)
{
- if (*current == id)
+ break;
+ }
+ if (!event->uses)
+ {
+ enumerator = array_create_enumerator(event->clients);
+ while (enumerator->enumerate(enumerator, &current))
{
- array_remove_at(event->clients, enumerator);
- found = TRUE;
- break;
+ if (*current == id)
+ {
+ array_remove_at(event->clients, enumerator);
+ found = TRUE;
+ break;
+ }
}
+ enumerator->destroy(enumerator);
+ break;
}
- enumerator->destroy(enumerator);
+ this->cond->wait(this->cond, this->mutex);
}
this->mutex->unlock(this->mutex);
@@ -340,11 +358,15 @@ CALLBACK(disconnect, void,
event_t *event;
u_int *current;
- /* deregister all clients */
+ /* deregister client from all events */
this->mutex->lock(this->mutex);
events = this->events->create_enumerator(this->events);
while (events->enumerate(events, NULL, &event))
{
+ while (event->uses)
+ {
+ this->cond->wait(this->cond, this->mutex);
+ }
ids = array_create_enumerator(event->clients);
while (ids->enumerate(ids, &current))
{