core: split nm_netns_watcher_remove_all()

The name suggests that the function always removes all the watchers
with the given tag; instead it removes only "dirty" ones when the
"all" parameter is FALSE. Split the function in two variants.

(cherry picked from commit b6e67c6abc)
This commit is contained in:
Beniamino Galvani
2025-02-20 13:43:50 +01:00
parent 39b7a8df91
commit a301c259f2
3 changed files with 22 additions and 11 deletions

View File

@@ -4960,7 +4960,7 @@ next:
} }
out: out:
nm_netns_watcher_remove_all(self->priv.netns, TAG, FALSE); nm_netns_watcher_remove_dirty(self->priv.netns, TAG);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -5841,12 +5841,8 @@ finalize(GObject *object)
gboolean changed; gboolean changed;
if (self->priv.netns) { if (self->priv.netns) {
nm_netns_watcher_remove_all(self->priv.netns, nm_netns_watcher_remove_all(self->priv.netns, _NETNS_WATCHER_IP_ADDR_TAG(self, AF_INET));
_NETNS_WATCHER_IP_ADDR_TAG(self, AF_INET), nm_netns_watcher_remove_all(self->priv.netns, _NETNS_WATCHER_IP_ADDR_TAG(self, AF_INET6));
TRUE);
nm_netns_watcher_remove_all(self->priv.netns,
_NETNS_WATCHER_IP_ADDR_TAG(self, AF_INET6),
TRUE);
} }
nm_prioq_destroy(&self->priv.p->failedobj_prioq); nm_prioq_destroy(&self->priv.p->failedobj_prioq);

View File

@@ -1369,8 +1369,8 @@ nm_netns_watcher_remove_handle(NMNetns *self, NMNetnsWatcherHandle *handle)
g_object_unref(self); g_object_unref(self);
} }
void static void
nm_netns_watcher_remove_all(NMNetns *self, gconstpointer tag, gboolean all) watcher_remove(NMNetns *self, gconstpointer tag, gboolean all)
{ {
NMNetnsPrivate *priv; NMNetnsPrivate *priv;
WatcherByTag *watcher_by_tag; WatcherByTag *watcher_by_tag;
@@ -1420,6 +1420,21 @@ nm_netns_watcher_remove_all(NMNetns *self, gconstpointer tag, gboolean all)
} }
} }
void
nm_netns_watcher_remove_all(NMNetns *self, gconstpointer tag)
{
watcher_remove(self, tag, TRUE);
}
/* Similar to nm_netns_watcher_remove_all(), but removes only watchers
* that were marked as "dirty" in a previous call of this function and were
* not added back via nm_netns_watcher_add() in the meantime. */
void
nm_netns_watcher_remove_dirty(NMNetns *self, gconstpointer tag)
{
watcher_remove(self, tag, FALSE);
}
/*****************************************************************************/ /*****************************************************************************/
static void static void

View File

@@ -98,7 +98,7 @@ void nm_netns_watcher_add(NMNetns *self,
NMNetnsWatcherCallback callback, NMNetnsWatcherCallback callback,
gpointer user_data); gpointer user_data);
void void nm_netns_watcher_remove_all(NMNetns *self, gconstpointer tag);
nm_netns_watcher_remove_all(NMNetns *self, gconstpointer tag, gboolean all /* or only dirty */); void nm_netns_watcher_remove_dirty(NMNetns *self, gconstpointer tag);
#endif /* __NM_NETNS_H__ */ #endif /* __NM_NETNS_H__ */