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.
This commit is contained in:
Thomas Haller 2020-07-29 19:26:05 +02:00
parent 43d031d37f
commit fea6be41cc
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 30 additions and 0 deletions

View file

@ -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

View file

@ -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))