[gnome-settings-daemon/benzea/rfkill-fixes: 2/2] rfkill-glib: Remove bluetooth rfkill change retry logic




commit 912158c7a643eeeedee2ab71110c7d27b4f1b57c
Author: Benjamin Berg <bberg redhat com>
Date:   Thu May 20 15:14:59 2021 +0200

    rfkill-glib: Remove bluetooth rfkill change retry logic
    
    This was always a buggy workaround for the fact that systemd-rfkill can
    end up immediately disabling an adapter that just appeared. This problem
    has been solved in systemd long ago though with commit 202cb8c396de
    ("rfkill: Delay writes until exit (#5768)").
    
    Completely remove the code. Note that the previous commit did indeed
    improve the logic a little bit so that we would reliably allow the user
    to escape such a situation. As such, one could consider leaving the code
    as-is purely as a reliability measure.

 plugins/rfkill/rfkill-glib.c | 96 +++-----------------------------------------
 1 file changed, 6 insertions(+), 90 deletions(-)
---
diff --git a/plugins/rfkill/rfkill-glib.c b/plugins/rfkill/rfkill-glib.c
index 3e1cc003..534634f0 100644
--- a/plugins/rfkill/rfkill-glib.c
+++ b/plugins/rfkill/rfkill-glib.c
@@ -65,12 +65,7 @@ struct _CcRfkillGlib {
        gboolean noinput;
        int noinput_fd;
 
-       /* Pending Bluetooth enablement.
-        * If (@change_all_timeout_id != 0), then (task != NULL). The converse
-        * does not necessarily hold. */
-       guint change_all_timeout_id;
        GTask *task;
-       gboolean write_all_again;
 };
 
 G_DEFINE_TYPE (CcRfkillGlib, cc_rfkill_glib, G_TYPE_OBJECT)
@@ -80,14 +75,6 @@ G_DEFINE_TYPE (CcRfkillGlib, cc_rfkill_glib, G_TYPE_OBJECT)
 static const char *type_to_string (unsigned int type);
 static void queue_write_change_all (CcRfkillGlib *rfkill);
 
-static void
-clear_current_task (CcRfkillGlib *rfkill)
-{
-       g_clear_object (&rfkill->task);
-       g_clear_handle_id (&rfkill->change_all_timeout_id, g_source_remove);
-       rfkill->write_all_again = FALSE;
-}
-
 static void
 cancel_current_task (CcRfkillGlib *rfkill)
 {
@@ -95,7 +82,7 @@ cancel_current_task (CcRfkillGlib *rfkill)
                g_cancellable_cancel (g_task_get_cancellable (rfkill->task));
        }
 
-       clear_current_task (rfkill);
+       g_clear_object (&rfkill->task);
 }
 
 /* Note that this can return %FALSE without setting @error. */
@@ -111,26 +98,6 @@ cc_rfkill_glib_send_change_all_event_finish (CcRfkillGlib        *rfkill,
        return g_task_propagate_boolean (G_TASK (res), error);
 }
 
-static gboolean
-write_change_all_timeout_cb (GTask *task)
-{
-       CcRfkillGlib *rfkill = g_task_get_source_object (task);
-
-       g_assert (rfkill->task == task);
-
-       g_debug ("Stopping to wait for more change events");
-
-       rfkill->change_all_timeout_id = 0;
-
-       /* Will be returned from write_change_all_done_cb */
-       if (!g_output_stream_has_pending (rfkill->stream)) {
-               g_task_return_boolean (rfkill->task, TRUE);
-               g_clear_object (&rfkill->task);
-       }
-
-       return G_SOURCE_REMOVE;
-}
-
 static void
 write_change_all_done_cb (GObject      *source_object,
                          GAsyncResult *res,
@@ -139,7 +106,6 @@ write_change_all_done_cb (GObject      *source_object,
        g_autoptr(GTask) task = G_TASK (user_data);
        CcRfkillGlib *rfkill = g_task_get_source_object (task);
        g_autoptr(GError) error = NULL;
-       gboolean returned = FALSE;
        gssize ret;
 
        g_debug ("Sending RFKILL_OP_CHANGE_ALL event done");
@@ -147,17 +113,14 @@ write_change_all_done_cb (GObject      *source_object,
        ret = g_output_stream_write_finish (G_OUTPUT_STREAM (source_object), res, &error);
        if (ret < 0) {
                g_task_return_error (task, g_steal_pointer (&error));
-               returned = TRUE;
-       } else if (task != rfkill->task ||
-                  !rfkill->change_all_timeout_id) {
+       } else {
                g_task_return_boolean (task, TRUE);
-               returned = TRUE;
        }
 
-       /* Clear current task if it was returned, otherwise, continue */
-       if (returned && (task == rfkill->task))
-               clear_current_task (rfkill);
-       else if (rfkill->write_all_again)
+       /* Clear current task if it was returned, otherwise, start the next one */
+       if (task == rfkill->task)
+               g_clear_object (&rfkill->task);
+       else if (rfkill->task)
                queue_write_change_all (rfkill);
 }
 
@@ -169,7 +132,6 @@ queue_write_change_all (CcRfkillGlib *rfkill)
 
        /* Operations are pending, we'll get a call to write_change_all_done_cb */
        if (g_output_stream_has_pending (rfkill->stream)) {
-               rfkill->write_all_again = TRUE;
                return;
        }
 
@@ -181,7 +143,6 @@ queue_write_change_all (CcRfkillGlib *rfkill)
                                     g_task_get_cancellable (rfkill->task),
                                     write_change_all_done_cb,
                                     g_object_ref (rfkill->task));
-       rfkill->write_all_again = FALSE;
 }
 
 void
@@ -223,21 +184,8 @@ cc_rfkill_glib_send_change_all_event (CcRfkillGlib        *rfkill,
 
        g_task_set_task_data (task, event, g_free);
        rfkill->task = g_object_ref (task);
-       rfkill->change_all_timeout_id = 0;
 
        queue_write_change_all (rfkill);
-
-       /* During this timeframe we'll send another change request if an event
-        * occurs.
-        * This works around cases wh */
-       if (event->type == RFKILL_TYPE_BLUETOOTH &&
-           event->soft == 0 &&
-           rfkill->change_all_timeout_id == 0) {
-               g_assert (rfkill->task == task);
-               rfkill->change_all_timeout_id = g_timeout_add (CHANGE_ALL_TIMEOUT,
-                                                              (GSourceFunc) write_change_all_timeout_cb,
-                                                              task);
-       }
 }
 
 static const char *
@@ -288,31 +236,6 @@ print_event (struct rfkill_event *event)
                 event->soft, event->hard);
 }
 
-static gboolean
-got_bt_off_change_event (GList *events)
-{
-       GList *l;
-
-       g_assert (events != NULL);
-
-       for (l = events ; l != NULL; l = l->next) {
-               struct rfkill_event *event = l->data;
-
-               if (event->op != RFKILL_OP_CHANGE)
-                       continue;
-
-               if (event->type == RFKILL_TYPE_BLUETOOTH)
-                       continue;
-
-               if (event->soft == 0)
-                       continue;
-
-               return TRUE;
-       }
-
-       return FALSE;
-}
-
 static void
 emit_changed_signal_and_free (CcRfkillGlib *rfkill,
                              GList        *events)
@@ -324,13 +247,6 @@ emit_changed_signal_and_free (CcRfkillGlib *rfkill,
                       signals[CHANGED],
                       0, events);
 
-       if (rfkill->change_all_timeout_id > 0 &&
-           got_bt_off_change_event (events)) {
-               g_debug ("Received a change event after a RFKILL_OP_CHANGE_ALL event, re-sending 
RFKILL_OP_CHANGE_ALL");
-
-               queue_write_change_all (rfkill);
-       }
-
        g_list_free_full (events, g_free);
 }
 


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