[gnome-control-center/gnome-3-38] fingerprint-dialog: Properly handle claiming errors if we're already claiming



commit 826268dd74323f3fd7d8955efe184c5bafafc0a0
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri Dec 11 01:39:38 2020 +0100

    fingerprint-dialog: Properly handle claiming errors if we're already claiming
    
    We were a bit too permissive in handling the AlreadyInUse error during
    claim, as we assumed it was always us causing it instead of properly
    handing the case a device was already claimed by another caller.
    
    So to ensure this is the case we need to avoid multiple calls to claim
    until we've finished one.
    
    Unfortunately we can't rely on a cancellable here as we may end up
    cancelling the request that succeeded and we'll only get an
    AlreadyClaimed error without know if it was us succeeding.
    
    Fixes: #1201

 panels/user-accounts/cc-fingerprint-dialog.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/panels/user-accounts/cc-fingerprint-dialog.c b/panels/user-accounts/cc-fingerprint-dialog.c
index 61b6d61d4..b7894c045 100644
--- a/panels/user-accounts/cc-fingerprint-dialog.c
+++ b/panels/user-accounts/cc-fingerprint-dialog.c
@@ -69,6 +69,7 @@ struct _CcFingerprintDialog
 
   CcFingerprintManager *manager;
   CcFprintdDevice      *device;
+  gboolean              claiming;
   gboolean              device_claimed;
   gulong                device_signal_id;
   gulong                device_name_owner_id;
@@ -1120,13 +1121,16 @@ claim_device_cb (GObject      *object,
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
     return;
 
+  self->claiming = FALSE;
+
   if (error)
     {
       g_autofree char *dbus_error = g_dbus_error_get_remote_error (error);
       g_autofree char *error_message = NULL;
 
-      if (dbus_error && g_str_has_suffix (dbus_error, ".Error.AlreadyInUse"))
-        self->device_claimed = TRUE;
+      if (dbus_error && g_str_has_suffix (dbus_error, ".Error.AlreadyInUse") &&
+          self->device_claimed)
+         return;
 
       g_dbus_error_strip_remote_error (error);
       error_message = g_strdup_printf (_("Failed to claim fingerprint device %s: %s"),
@@ -1152,8 +1156,14 @@ claim_device (CcFingerprintDialog *self)
 {
   ActUser *user;
 
+  g_return_if_fail (!self->device_claimed);
+
+  if (self->claiming)
+    return;
+
   user = cc_fingerprint_manager_get_user (self->manager);
   gtk_widget_set_sensitive (self->prints_manager, FALSE);
+  self->claiming = TRUE;
 
   cc_fprintd_device_call_claim (self->device,
                                 act_user_get_user_name (user),


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