[mutter] Throw an error in case of unsupported session type



commit 4ed59a020d76a0a0a5910de22a227f2b093bf551
Author: Jouke Witteveen <j witteveen gmail com>
Date:   Mon Jun 27 12:51:15 2016 +0200

    Throw an error in case of unsupported session type
    
    When launching a GNOME session from a text-mode VT, the logind session
    type is unlikely to be set to either "wayland" or "x11". We search for a
    supported session type first with logind and then with
    $XDG_SESSION_TYPE. As a fallback, we also test $DISPLAY in case of a
    "tty" logind session to support starting through xinit. Ideally, such
    setups should set XDG_SESSION_TYPE=x11.
    If no supported session type is found, we throw an error.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759388

 src/core/main.c |   87 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 54 insertions(+), 33 deletions(-)
---
diff --git a/src/core/main.c b/src/core/main.c
index bd81604..25586be 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -304,50 +304,75 @@ on_sigterm (gpointer user_data)
 }
 
 #if defined(HAVE_WAYLAND) && defined(HAVE_NATIVE_BACKEND)
+static gboolean
+session_type_is_supported (const char *session_type)
+{
+   return (g_strcmp0 (session_type, "x11") == 0) ||
+          (g_strcmp0 (session_type, "wayland") == 0);
+}
+
 static char *
-find_logind_session_type (void)
+find_session_type (void)
 {
-  char **sessions;
+  char **sessions = NULL;
   char *session_id;
   char *session_type;
+  const char *session_type_env;
+  gboolean is_tty = FALSE;
   int ret, i;
 
   ret = sd_pid_get_session (0, &session_id);
-
   if (ret == 0 && session_id != NULL)
     {
       ret = sd_session_get_type (session_id, &session_type);
       free (session_id);
 
-      if (ret < 0)
-        session_type = NULL;
-
-      goto out;
+      if (ret == 0)
+        {
+          if (session_type_is_supported (session_type))
+            goto out;
+          else
+            is_tty = g_strcmp0 (session_type, "tty") == 0;
+          free (session_type);
+        }
     }
-  session_type = NULL;
-
-  ret = sd_uid_get_sessions (getuid (), TRUE, &sessions);
+  else if (sd_uid_get_sessions (getuid (), 1, &sessions) > 0)
+    {
+      for (i = 0; sessions[i] != NULL; i++)
+        {
+          ret = sd_session_get_type (sessions[i], &session_type);
 
-  if (ret < 0 || sessions == NULL)
-    goto out;
+          if (ret < 0)
+            continue;
 
-  for (i = 0; sessions[i] != NULL; i++)
-    {
-      ret = sd_session_get_type (sessions[i], &session_type);
+          if (session_type_is_supported (session_type))
+            {
+              g_strfreev (sessions);
+              goto out;
+            }
 
-      if (ret < 0)
-        continue;
+          free (session_type);
+        }
+    }
+  g_strfreev (sessions);
 
-      if (g_strcmp0 (session_type, "x11") == 0||
-          g_strcmp0 (session_type, "wayland") == 0)
-        break;
+  session_type_env = g_getenv ("XDG_SESSION_TYPE");
+  if (session_type_is_supported (session_type_env))
+    {
+      /* The string should be freeable */
+      session_type = strdup (session_type_env);
+      goto out;
+    }
 
-      g_clear_pointer (&session_type, (GDestroyNotify) free);
+  /* Legacy support for starting through xinit */
+  if (is_tty && (g_getenv ("MUTTER_DISPLAY") || g_getenv ("DISPLAY")))
+    {
+      session_type = strdup ("x11");
+      goto out;
     }
 
-  for (i = 0; sessions[i] != NULL; i++)
-    free (sessions[i]);
-  free (sessions);
+  meta_warning ("Unsupported session type\n");
+  meta_exit (META_EXIT_ERROR);
 
 out:
   return session_type;
@@ -356,16 +381,12 @@ out:
 static gboolean
 check_for_wayland_session_type (void)
 {
-  char *session_type = NULL;
-  gboolean is_wayland = FALSE;
-
-  session_type = find_logind_session_type ();
+  char *session_type;
+  gboolean is_wayland;
 
-  if (session_type != NULL)
-    {
-      is_wayland = g_strcmp0 (session_type, "wayland") == 0;
-      free (session_type);
-    }
+  session_type = find_session_type ();
+  is_wayland = g_strcmp0 (session_type, "wayland") == 0;
+  free (session_type);
 
   return is_wayland;
 }


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