[gnome-settings-daemon/gnome-3-28] rfkill: Create nested cancellable for rfkill setting



commit 07b71f6aa807e82073e8e440cfdb964462f7c1ed
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Jul 17 11:17:54 2018 +0200

    rfkill: Create nested cancellable for rfkill setting
    
    The rfkill code will cancel any running task when a new task comes in.
    This makes sense in most cases, but the code would cancel the
    cancellable from the outside scope which may be reused. This effectively
    resulted in all changes to be cancelled immediately when this
    compression happened once.
    
    Fix the issue by creating a new cancellable and propagating the
    cancelled state rather then setting it on the passed in cancellable.

 plugins/rfkill/rfkill-glib.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/plugins/rfkill/rfkill-glib.c b/plugins/rfkill/rfkill-glib.c
index 450e6533..259bafc0 100644
--- a/plugins/rfkill/rfkill-glib.c
+++ b/plugins/rfkill/rfkill-glib.c
@@ -191,11 +191,21 @@ cc_rfkill_glib_send_change_all_event (CcRfkillGlib        *rfkill,
 {
        g_autoptr(GTask) task = NULL;
        struct rfkill_event *event;
+       g_autoptr(GCancellable) task_cancellable = NULL;
 
        g_return_if_fail (CC_RFKILL_IS_GLIB (rfkill));
        g_return_if_fail (rfkill->stream);
 
-       task = g_task_new (rfkill, cancellable, callback, user_data);
+       task_cancellable = g_cancellable_new ();
+       g_signal_connect_object (cancellable, "cancelled",
+                                (GCallback) g_cancellable_cancel,
+                                task_cancellable,
+                                G_CONNECT_SWAPPED);
+       /* Now check if it is cancelled already */
+       if (g_cancellable_is_cancelled (cancellable))
+               g_cancellable_cancel (task_cancellable);
+
+       task = g_task_new (rfkill, task_cancellable, callback, user_data);
        g_task_set_source_tag (task, cc_rfkill_glib_send_change_all_event);
 
        /* Clear any previous task. */
@@ -215,7 +225,7 @@ cc_rfkill_glib_send_change_all_event (CcRfkillGlib        *rfkill,
        g_output_stream_write_async (rfkill->stream,
                                     event, sizeof(struct rfkill_event),
                                     G_PRIORITY_DEFAULT,
-                                    cancellable, write_change_all_done_cb,
+                                    task_cancellable, write_change_all_done_cb,
                                     g_object_ref (task));
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]