summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2018-07-17 11:17:54 +0200
committerBenjamin Berg <benjamin@sipsolutions.net>2018-08-08 11:35:12 +0000
commit54395ff0951f408914261793ec57c0a72ff6aa23 (patch)
tree90f2d005b74c44539a5896d74859ee2eacaed9a4
parent3651ab09d085b4063762230e0e7491ab918a6c9f (diff)
downloadgnome-settings-daemon-54395ff0951f408914261793ec57c0a72ff6aa23.tar.gz
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.
-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));
}