[gvfs] afc: Lock apps mutex when setting up HouseArrest



commit 6fe89ebd7ede76bfb98f93907fd92305e6de7cc4
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Mar 23 19:00:42 2016 +0100

    afc: Lock apps mutex when setting up HouseArrest
    
    So that we don't have cases where the AppInfo disappears from under us.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676188

 daemon/gvfsbackendafc.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/daemon/gvfsbackendafc.c b/daemon/gvfsbackendafc.c
index e337efc..d7048f0 100644
--- a/daemon/gvfsbackendafc.c
+++ b/daemon/gvfsbackendafc.c
@@ -777,18 +777,20 @@ g_vfs_backend_setup_afc_for_app (GVfsBackendAfc *self,
   plist_t dict, error;
   lockdownd_error_t lerr;
 
+  g_mutex_lock (&self->apps_lock);
+
   info = g_hash_table_lookup (self->apps, id);
 
   if (info == NULL ||
       info->afc_cli != NULL)
-    return;
+    goto out;
 
   /* Load house arrest and afc now! */
   lockdown_cli = NULL;
   if (lockdownd_client_new_with_handshake (self->dev, &lockdown_cli, "gvfsd-afc") != LOCKDOWN_E_SUCCESS)
     {
       g_warning ("Failed to get a lockdown to start house arrest for app %s", info->id);
-      return;
+      goto out;
     }
 
   lerr = lockdownd_start_service (lockdown_cli, "com.apple.mobile.house_arrest", &lockdown_service);
@@ -796,7 +798,7 @@ g_vfs_backend_setup_afc_for_app (GVfsBackendAfc *self,
     {
       lockdownd_client_free (lockdown_cli);
       g_warning ("Failed to start house arrest for app %s (%d)", info->id, lerr);
-      return;
+      goto out;
     }
 
   house_arrest = NULL;
@@ -806,7 +808,7 @@ g_vfs_backend_setup_afc_for_app (GVfsBackendAfc *self,
       g_warning ("Failed to start house arrest client for app %s", info->id);
       lockdownd_client_free (lockdown_cli);
       lockdownd_service_descriptor_free (lockdown_service);
-      return;
+      goto out;
     }
 
   lockdownd_service_descriptor_free (lockdown_service);
@@ -818,7 +820,7 @@ g_vfs_backend_setup_afc_for_app (GVfsBackendAfc *self,
       g_warning ("Failed to set up house arrest for app %s", info->id);
       house_arrest_client_free (house_arrest);
       lockdownd_client_free (lockdown_cli);
-      return;
+      goto out;
     }
   error = plist_dict_get_item (dict, "Error");
   if (error != NULL)
@@ -832,7 +834,7 @@ g_vfs_backend_setup_afc_for_app (GVfsBackendAfc *self,
 
       house_arrest_client_free (house_arrest);
       lockdownd_client_free (lockdown_cli);
-      return;
+      goto out;
     }
   plist_free (dict);
 
@@ -844,12 +846,14 @@ g_vfs_backend_setup_afc_for_app (GVfsBackendAfc *self,
     {
       g_warning ("Failed to set up afc client for app %s", info->id);
       house_arrest_client_free (house_arrest);
-
-      return;
+      goto out;
     }
 
   info->house_arrest = house_arrest;
   info->afc_cli = afc;
+
+out:
+  g_mutex_unlock (&self->apps_lock);
 }
 
 /* If force_afc_mount is TRUE, then we'll try to mount


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