proper thread cancellation when using the charon->interfaces

This commit is contained in:
Martin Willi
2007-05-23 09:08:13 +00:00
parent 0f6b068259
commit 76042f8471
8 changed files with 100 additions and 5 deletions
+15
View File
@@ -238,6 +238,14 @@ static bool unroute_listener(interface_bus_listener_t *this, signal_t signal,
return TRUE;
}
/**
* remove a previously registered listener from the bus
*/
static void remove_listener(interface_bus_listener_t *listener)
{
charon->bus->remove_listener(charon->bus, &listener->listener);
}
/**
* Implementation of interface_manager_t.initiate.
*/
@@ -259,6 +267,7 @@ static status_t initiate(private_interface_manager_t *this,
{
ike_sa->set_peer_cfg(ike_sa, peer_cfg);
}
peer_cfg->destroy(peer_cfg);
listener.listener.signal = (void*)initiate_listener;
listener.callback = callback;
@@ -297,8 +306,10 @@ static status_t initiate(private_interface_manager_t *this,
retval = NEED_MORE;
break;
}
pthread_cleanup_push((void*)remove_listener, &listener);
signal = charon->bus->listen(charon->bus, &level, &thread,
&current, &format, &args);
pthread_cleanup_pop(0);
/* ike_sa is a valid pointer until we get one of the signals */
if (ike_sa == current)
{
@@ -373,8 +384,10 @@ static status_t terminate_ike(interface_manager_t *this, u_int32_t unique_id,
status = NEED_MORE;
break;
}
pthread_cleanup_push((void*)remove_listener, &listener);
signal = charon->bus->listen(charon->bus, &level, &thread,
&current, &format, &args);
pthread_cleanup_pop(0);
/* even if we checked in the IKE_SA, the pointer is valid until
* we get an IKE_DOWN_... */
@@ -475,8 +488,10 @@ static status_t terminate_child(interface_manager_t *this, u_int32_t reqid,
status = NEED_MORE;
break;
}
pthread_cleanup_push((void*)remove_listener, &listener);
signal = charon->bus->listen(charon->bus, &level, &thread,
&current, &format, &args);
pthread_cleanup_pop(0);
/* even if we checked in the IKE_SA, the pointer is valid until
* we get an IKE_DOWN_... */
if (ike_sa == current)
+8
View File
@@ -84,6 +84,10 @@ struct interface_manager_t {
/**
* @brief Initiate a CHILD_SA, and if required, an IKE_SA.
*
* The inititate() function is synchronous and thus blocks until the
* IKE_SA is established or failed. Because of this, the initiate() function
* contains a thread cancellation point.
*
* @param this calling object
* @param peer_cfg peer_cfg to use for IKE_SA setup
* @param child_cfg child_cfg to set up CHILD_SA from
@@ -101,6 +105,10 @@ struct interface_manager_t {
/**
* @brief Terminate an IKE_SA and all of its CHILD_SAs.
*
* The terminate() function is synchronous and thus blocks until the
* IKE_SA is properly deleted, or the delete timed out.
* The terminate() function contains a thread cancellation point.
*
* @param this calling object
* @param unique_id unique id of the IKE_SA to terminate.
* @param cb logging callback
@@ -206,9 +206,11 @@ static bool start_connection(private_dbus_interface_t *this, DBusMessage* msg)
{
status = charon->interfaces->initiate(charon->interfaces, peer_cfg,
child_cfg, dbus_log, NULL);
peer_cfg->destroy(peer_cfg);
}
child_cfg->destroy(child_cfg);
else
{
peer_cfg->destroy(peer_cfg);
}
}
reply = dbus_message_new_method_return(msg);
dbus_connection_send(this->conn, reply, NULL);
@@ -784,8 +784,6 @@ static void stroke_initiate(private_stroke_interface_t *this,
charon->interfaces->initiate(charon->interfaces, peer_cfg, child_cfg,
(interface_manager_cb_t)stroke_log, &info);
peer_cfg->destroy(peer_cfg);
child_cfg->destroy(child_cfg);
}
/**