summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2018-07-17 11:17:54 +0200
committerBenjamin Berg <bberg@redhat.com>2018-08-08 16:40:00 +0200
commit07b71f6aa807e82073e8e440cfdb964462f7c1ed (patch)
treebdd8b2cc0ae3fbfc9d263137e1aa90ce0a1f1367
parent409a4fe89455c2de8781ddbd3d18c0244aa1fd11 (diff)
downloadgnome-settings-daemon-gnome-3-28.tar.gz
rfkill: Create nested cancellable for rfkill settinggnome-3-28
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.
-rw-r--r--plugins/rfkill/rfkill-glib.c14
1 files 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));
}