summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-29 19:26:05 +0200
committerThomas Haller <thaller@redhat.com>2020-08-05 12:47:55 +0200
commitfea6be41cc6ec882dbe911dc14e31a44ab20ed36 (patch)
tree3855a909eb5f604c05d5d4bd312ef8a8c242b9a1
parent43d031d37f8a9620147347d21b99c33658996407 (diff)
downloadNetworkManager-fea6be41cc6ec882dbe911dc14e31a44ab20ed36.tar.gz
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.
-rw-r--r--src/nm-dbus-object.c28
-rw-r--r--src/nm-dbus-object.h2
2 files changed, 30 insertions, 0 deletions
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))