dispatcher: cleanup nm_dispatcher_call_cancel()

Remove the call-id from the requests hash before invoking the callback.
This prevents the user to cancel the request from within the callback.
Supporting such a use case is not necessary so prevent it and tighten
the callers up.
This commit is contained in:
Thomas Haller 2019-05-23 16:51:42 +02:00
parent 3dbda5addc
commit 55be5166f0
2 changed files with 19 additions and 19 deletions

View file

@ -12375,17 +12375,18 @@ nm_device_get_ip6_config (NMDevice *self)
/*****************************************************************************/
static void
static gboolean
dispatcher_cleanup (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->dispatcher.call_id) {
nm_dispatcher_call_cancel (priv->dispatcher.call_id);
priv->dispatcher.call_id = NULL;
priv->dispatcher.post_state = NM_DEVICE_STATE_UNKNOWN;
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
}
if (!priv->dispatcher.call_id)
return FALSE;
nm_dispatcher_call_cancel (g_steal_pointer (&priv->dispatcher.call_id));
priv->dispatcher.post_state = NM_DEVICE_STATE_UNKNOWN;
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
return TRUE;
}
static void
@ -12397,7 +12398,8 @@ dispatcher_complete_proceed_state (NMDispatcherCallId *call_id, gpointer user_da
g_return_if_fail (call_id == priv->dispatcher.call_id);
priv->dispatcher.call_id = NULL;
nm_device_queue_state (self, priv->dispatcher.post_state,
nm_device_queue_state (self,
priv->dispatcher.post_state,
priv->dispatcher.post_state_reason);
priv->dispatcher.post_state = NM_DEVICE_STATE_UNKNOWN;
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
@ -12410,10 +12412,8 @@ ip_check_pre_up (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->dispatcher.call_id != 0) {
g_warn_if_reached ();
dispatcher_cleanup (self);
}
if (dispatcher_cleanup (self))
nm_assert_not_reached ();
priv->dispatcher.post_state = NM_DEVICE_STATE_SECONDARIES;
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;

View file

@ -92,10 +92,7 @@ static void
_init_dispatcher (void)
{
if (G_UNLIKELY (gl.requests == NULL)) {
gl.requests = g_hash_table_new_full (nm_direct_hash,
NULL,
NULL,
(GDestroyNotify) dispatcher_call_id_free);
gl.requests = g_hash_table_new (nm_direct_hash, NULL);
gl.dbus_connection = nm_g_object_ref (NM_MAIN_DBUS_CONNECTION_GET);
if (!gl.dbus_connection)
@ -423,10 +420,12 @@ dispatcher_done_cb (GObject *source, GAsyncResult *result, gpointer user_data)
} else
dispatcher_results_process (call_id->request_id, call_id->action, ret);
g_hash_table_remove (gl.requests, call_id);
if (call_id->callback)
call_id->callback (call_id, call_id->user_data);
g_hash_table_remove (gl.requests, call_id);
dispatcher_call_id_free (call_id);
}
static const char *action_table[] = {
@ -447,8 +446,9 @@ static const char *action_table[] = {
static const char *
action_to_string (NMDispatcherAction action)
{
g_assert ((gsize) action < G_N_ELEMENTS (action_table));
return action_table[action];
if (G_UNLIKELY ((gsize) action >= G_N_ELEMENTS (action_table)))
g_return_val_if_reached (NULL);
return action_table[(gsize) action];
}
static gboolean