From fea6be41cc6ec882dbe911dc14e31a44ab20ed36 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Jul 2020 19:26:05 +0200 Subject: [PATCH] core: add nm_dbus_object_unexport_on_idle() helper It's important that we don't unexport an object, until all our references to the path are cleared. That is not so easy to guarantee, so add a helper method to unexport on an idle handler. In many cases there is little harm in delaying an object going away. --- src/nm-dbus-object.c | 28 ++++++++++++++++++++++++++++ src/nm-dbus-object.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/nm-dbus-object.c b/src/nm-dbus-object.c index a133268600..db793b9da3 100644 --- a/src/nm-dbus-object.c +++ b/src/nm-dbus-object.c @@ -8,6 +8,7 @@ #include "nm-dbus-object.h" #include "nm-dbus-manager.h" +#include "NetworkManagerUtils.h" /*****************************************************************************/ @@ -144,6 +145,33 @@ nm_dbus_object_unexport (NMDBusObject *self) self->internal.is_unexporting = FALSE; } +static gboolean +_unexport_on_idle_cb (gpointer user_data) +{ + gs_unref_object NMDBusObject *self = user_data; + + nm_dbus_object_unexport (self); + return G_SOURCE_REMOVE; +} + +void +nm_dbus_object_unexport_on_idle (NMDBusObject *self_take) +{ + g_return_if_fail (NM_IS_DBUS_OBJECT (self_take)); + + g_return_if_fail (self_take->internal.path); + + /* There is no mechanism to cancel or abort the unexport. It will always + * gonna happen. + * + * However, we register it to block shutdown, so that we ensure that it will happen. */ + + nm_shutdown_wait_obj_register_object (self_take, "unexport-dbus-obj-on-idle"); + + g_idle_add (_unexport_on_idle_cb, + g_steal_pointer (&self_take)); +} + /*****************************************************************************/ void diff --git a/src/nm-dbus-object.h b/src/nm-dbus-object.h index 8b36bce897..ab09465f6c 100644 --- a/src/nm-dbus-object.h +++ b/src/nm-dbus-object.h @@ -166,6 +166,8 @@ nm_dbus_object_get_path_still_exported (NMDBusObject *self) const char *nm_dbus_object_export (NMDBusObject *self); void nm_dbus_object_unexport (NMDBusObject *self); +void nm_dbus_object_unexport_on_idle (NMDBusObject *self_take); + void _nm_dbus_object_clear_and_unexport (NMDBusObject **location); #define nm_dbus_object_clear_and_unexport(location) _nm_dbus_object_clear_and_unexport ((NMDBusObject **) (location))