From c984f0f2833a20da3853a73d7c50f6c7c98d61d9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 5 Apr 2018 09:24:22 +0200 Subject: [PATCH] auth-chain: split handling auth-call in idle auth_call_complete() had two callers: once from the idle handler, and once from pk_call_cb(). The conditions are slightly different, split the function in two. For one, this allows to unset the obsolete call_idle_id. --- src/nm-auth-utils.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/nm-auth-utils.c b/src/nm-auth-utils.c index e2f1e12c81..4594537cba 100644 --- a/src/nm-auth-utils.c +++ b/src/nm-auth-utils.c @@ -62,6 +62,16 @@ typedef struct { /*****************************************************************************/ +static void +_ASSERT_call (AuthCall *call) +{ + nm_assert (call); + nm_assert (call->chain); + nm_assert (nm_c_list_contains_entry (&call->chain->auth_call_lst_head, call, auth_call_lst)); +} + +/*****************************************************************************/ + static void auth_call_free (AuthCall *call) { @@ -207,18 +217,15 @@ auth_chain_finish (gpointer user_data) return FALSE; } -static gboolean +static void auth_call_complete (AuthCall *call) { NMAuthChain *self; - nm_assert (call); + _ASSERT_call (call); self = call->chain; - nm_assert (self); - nm_assert (nm_c_list_contains_entry (&self->auth_call_lst_head, call, auth_call_lst)); - c_list_unlink (&call->auth_call_lst); if (c_list_is_empty (&self->auth_call_lst_head)) { @@ -227,6 +234,17 @@ auth_call_complete (AuthCall *call) } auth_call_free (call); +} + +static gboolean +auth_call_complete_idle_cb (gpointer user_data) +{ + AuthCall *call = user_data; + + _ASSERT_call (call); + + call->call_idle_id = 0; + auth_call_complete (call); return G_SOURCE_REMOVE; } @@ -298,7 +316,7 @@ nm_auth_chain_add_call (NMAuthChain *self, || !nm_auth_manager_get_polkit_enabled (auth_manager)) { /* Root user or non-polkit always gets the permission */ nm_auth_chain_set_data (self, permission, GUINT_TO_POINTER (NM_AUTH_CALL_RESULT_YES), NULL); - call->call_idle_id = g_idle_add ((GSourceFunc) auth_call_complete, call); + call->call_idle_id = g_idle_add (auth_call_complete_idle_cb, call); } else { /* Non-root always gets authenticated when using polkit */ #if WITH_POLKIT @@ -316,7 +334,7 @@ nm_auth_chain_add_call (NMAuthChain *self, NM_MANAGER_ERROR_FAILED, "Polkit support is disabled at compile time"); } - call->call_idle_id = g_idle_add ((GSourceFunc) auth_call_complete, call); + call->call_idle_id = g_idle_add (auth_call_complete_idle_cb, call); #endif } }