summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/NetworkManagerUtils.c42
-rw-r--r--src/NetworkManagerUtils.h3
2 files changed, 45 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index 3f2f44d3cd..9f88e0ab81 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -954,6 +954,43 @@ struct _NMShutdownWaitObjHandle {
static CList _shutdown_waitobj_lst_head;
+static int _shutdown_is_quitting = 0;
+
+static gboolean
+_shutdown_cancel_on_idle_cb (gpointer user_data)
+{
+ gs_unref_object GCancellable *cancellable = user_data;
+
+ g_cancellable_cancel (cancellable);
+ return G_SOURCE_REMOVE;
+}
+
+static void
+_shutdown_cancel_on_idle (GCancellable *cancellable)
+{
+ g_idle_add (_shutdown_cancel_on_idle_cb, g_object_ref (cancellable));
+}
+
+void
+_nm_shutdown_set_quitting (void)
+{
+ NMShutdownWaitObjHandle *handle;
+
+ if (!g_atomic_int_compare_and_exchange (&_shutdown_is_quitting, 0, 1))
+ return;
+
+ c_list_for_each_entry (handle, &_shutdown_waitobj_lst_head, lst) {
+ if (handle->is_cancellable)
+ _shutdown_cancel_on_idle (handle->watched_obj);
+ }
+}
+
+gboolean
+nm_shutdown_is_quitting (void)
+{
+ return g_atomic_int_get (&_shutdown_is_quitting) != 0;
+}
+
static void
_shutdown_waitobj_unregister (NMShutdownWaitObjHandle *handle)
{
@@ -1051,6 +1088,11 @@ nm_shutdown_wait_obj_register_full (gpointer watched_obj,
c_list_link_tail (&_shutdown_waitobj_lst_head, &handle->lst);
if (watched_obj)
g_object_weak_ref (watched_obj, _shutdown_waitobj_cb, handle);
+
+ if ( wait_type == NM_SHUTDOWN_WAIT_TYPE_CANCELLABLE
+ && nm_shutdown_is_quitting ())
+ _shutdown_cancel_on_idle (watched_obj);
+
return handle;
}
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index 558a262b98..c8894e47c0 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -126,6 +126,9 @@ nm_shutdown_wait_obj_register_cancellable_full (GCancellable *watched_obj,
void nm_shutdown_wait_obj_unregister (NMShutdownWaitObjHandle *handle);
+void _nm_shutdown_set_quitting (void);
+gboolean nm_shutdown_is_quitting (void);
+
/*****************************************************************************/
const char *