diff options
author | Benjamin Berg <bberg@redhat.com> | 2018-07-17 11:17:54 +0200 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2018-07-17 11:24:08 +0200 |
commit | e61866f7bf6c08dfcaf3a1c1be247704d3ec8144 (patch) | |
tree | d866576cb0df1b83f00187ec780a4099dcb67ae5 | |
parent | 6417d8185dc825f837173a5c751f715b16483c5a (diff) | |
download | gnome-settings-daemon-benzea/fix-rfkill-cancelling.tar.gz |
rfkill: Create nested cancellable for rfkill settingbenzea/fix-rfkill-cancelling
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.c | 14 |
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)); } |