[gvfs/wip/oholy/admin-hang] admin: Fix mount operation hang caused by pkexec failure




commit 6d49a976cadd12ce41e275f141a072777975e527
Author: Ondrej Holy <oholy redhat com>
Date:   Wed May 12 10:29:14 2021 +0200

    admin: Fix mount operation hang caused by pkexec failure
    
    Currently, the mount operation for the admin backend can hang when the
    authentication dialog is dismissed for example. This is because `pkexec`
    exits before spawning the `gvfsd-admin` daemon. Let's catch that case
    and return the "Permission denied" error.
    
    Fixes: https://gitlab.gnome.org/GNOME/gvfs/-/issues/565

 daemon/mount.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/daemon/mount.c b/daemon/mount.c
index 33cae597..db271dd3 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -415,6 +415,30 @@ child_watch_cb (GPid pid,
                 gint status,
                 gpointer user_data)
 {
+  MountData *data = user_data;
+  GError *error = NULL;
+  gint code = 0;
+
+  if (!g_spawn_check_exit_status (status, &error))
+    {
+      if (error->domain == G_SPAWN_EXIT_ERROR)
+        code = error->code;
+
+      g_clear_error (&error);
+    }
+
+  /* GVfs daemons always exit with 0, but gvfsd-admin is spawned over pkexec,
+   * which can fail when the authentication dialog is dismissed for example.
+   */
+  if (code == 126 || code == 127)
+    {
+      error = g_error_new_literal (G_IO_ERROR,
+                                   G_IO_ERROR_PERMISSION_DENIED,
+                                   _("Permission denied"));
+      mount_finish (data, error);
+      g_error_free (error);
+    }
+
   g_spawn_close_pid (pid);
 }
 
@@ -485,7 +509,7 @@ spawn_mount (MountData *data)
         }
       else
         {
-          g_child_watch_add (pid, child_watch_cb, NULL);
+          g_child_watch_add (pid, child_watch_cb, data);
         }
 
       g_strfreev (argv);


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