auth-chain: avoid another idle-call when auth-request completes

NMAuthChain schedules (possibly) multiple authentication requests.
When they all complete, it will once invoke the result-callback.

There is no need to schedule this result-callback on another idle-handler,
because nm_auth_manager_polkit_authority_check_authorization() should guarantee
to invoke the callback never-synchronously and on a clean call-stack (to avoid
problems with re-entrancy). At that point, NMAuthChain does not need to
delay this further.
This commit is contained in:
Thomas Haller
2018-04-09 12:36:06 +02:00
parent 50b74731f6
commit 290d02536c
2 changed files with 15 additions and 17 deletions

View File

@@ -240,6 +240,9 @@ _call_check_authorization (CheckAuthData *data)
data->dbus_parameters = NULL; data->dbus_parameters = NULL;
} }
/*
* @callback must never be invoked synchronously.
*/
void void
nm_auth_manager_polkit_authority_check_authorization (NMAuthManager *self, nm_auth_manager_polkit_authority_check_authorization (NMAuthManager *self,
NMAuthSubject *subject, NMAuthSubject *subject,

View File

@@ -44,8 +44,6 @@ struct NMAuthChain {
NMAuthChainResultFunc done_func; NMAuthChainResultFunc done_func;
gpointer user_data; gpointer user_data;
guint idle_id;
guint32 refcount; guint32 refcount;
bool done:1; bool done:1;
@@ -209,16 +207,15 @@ nm_auth_chain_get_subject (NMAuthChain *self)
/*****************************************************************************/ /*****************************************************************************/
static gboolean static gboolean
auth_chain_finish (gpointer user_data) auth_chain_finish (NMAuthChain *self)
{ {
NMAuthChain *self = user_data;
self->idle_id = 0;
self->done = TRUE; self->done = TRUE;
/* Ensure we stay alive across the callback */ /* Ensure we stay alive across the callback */
nm_assert (self->refcount == 1);
self->refcount++; self->refcount++;
self->done_func (self, NULL, self->context, self->user_data); self->done_func (self, NULL, self->context, self->user_data);
nm_assert (NM_IN_SET (self->refcount, 1, 2));
nm_auth_chain_destroy (self); nm_auth_chain_destroy (self);
return FALSE; return FALSE;
} }
@@ -232,14 +229,14 @@ auth_call_complete (AuthCall *call)
self = call->chain; self = call->chain;
c_list_unlink (&call->auth_call_lst); nm_assert (!self->done);
if (c_list_is_empty (&self->auth_call_lst_head)) {
nm_assert (!self->idle_id && !self->done);
self->idle_id = g_idle_add (auth_chain_finish, self);
}
auth_call_free (call); auth_call_free (call);
if (c_list_is_empty (&self->auth_call_lst_head)) {
/* we are on an idle-handler or a clean call-stack (non-reentrant). */
auth_chain_finish (self);
}
} }
static gboolean static gboolean
@@ -307,10 +304,10 @@ nm_auth_chain_add_call (NMAuthChain *self,
NMAuthManager *auth_manager = nm_auth_manager_get (); NMAuthManager *auth_manager = nm_auth_manager_get ();
g_return_if_fail (self); g_return_if_fail (self);
g_return_if_fail (permission && *permission);
g_return_if_fail (self->subject); g_return_if_fail (self->subject);
g_return_if_fail (!self->done);
g_return_if_fail (permission && *permission);
g_return_if_fail (nm_auth_subject_is_unix_process (self->subject) || nm_auth_subject_is_internal (self->subject)); g_return_if_fail (nm_auth_subject_is_unix_process (self->subject) || nm_auth_subject_is_internal (self->subject));
g_return_if_fail (!self->idle_id && !self->done);
call = g_slice_new0 (AuthCall); call = g_slice_new0 (AuthCall);
call->chain = self; call->chain = self;
@@ -412,13 +409,11 @@ nm_auth_chain_destroy (NMAuthChain *self)
AuthCall *call; AuthCall *call;
g_return_if_fail (self); g_return_if_fail (self);
g_return_if_fail (self->refcount > 0); g_return_if_fail (NM_IN_SET (self->refcount, 1, 2));
if (--self->refcount > 0) if (--self->refcount > 0)
return; return;
nm_clear_g_source (&self->idle_id);
nm_clear_g_object (&self->subject); nm_clear_g_object (&self->subject);
nm_clear_g_object (&self->context); nm_clear_g_object (&self->context);