auth-chain: track auth-chains in embedded CList

NMManager and NMSettings both may have multiple authorization requests
ongoing. They need to keep track of them, at the very least to be able
to cancel them on shutdown.

Since NMAuthChain is not ref-countable, it always has only one clear
user/owner. It makes little sense otherwise. Since most callers already
want to track their NMAuthChain instances, let NMAuthChain help with that.

Embed a "parent" CList field inside NMAuthChain. This avoids requiring
an additional GSList allocation to track the element. Also, it allows to
link and append an element without iterating the list.

This ties the caller and the NMAuthChain a bit tighter together (making them
less indepdendent). Generally that is not desirable. But here it seems the
logic (of tracking the NMAuthChain) is still trivial and well separated.
It's just that NMAuthChain instances now can be linked in a CList.
This commit is contained in:
Thomas Haller
2019-05-26 18:49:55 +02:00
parent a63714ec1d
commit 142c1215ee
4 changed files with 66 additions and 36 deletions

View File

@@ -30,6 +30,9 @@
/*****************************************************************************/
struct NMAuthChain {
CList parent_lst;
CList data_lst_head;
CList auth_call_lst_head;
@@ -46,6 +49,8 @@ struct NMAuthChain {
bool is_finishing:1;
};
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMAuthChain, parent_lst) == 0);
typedef struct {
CList auth_call_lst;
NMAuthChain *chain;
@@ -435,6 +440,7 @@ nm_auth_chain_new_subject (NMAuthSubject *subject,
.user_data = user_data,
.context = nm_g_object_ref (context),
.subject = g_object_ref (subject),
.parent_lst = C_LIST_INIT (self->parent_lst),
.data_lst_head = C_LIST_INIT (self->data_lst_head),
.auth_call_lst_head = C_LIST_INIT (self->auth_call_lst_head),
};
@@ -479,6 +485,8 @@ _auth_chain_destroy (NMAuthChain *self)
AuthCall *call;
ChainData *chain_data;
c_list_unlink (&self->parent_lst);
nm_clear_g_object (&self->subject);
nm_clear_g_object (&self->context);