--- gdm-2.27.90/daemon/gdm-session-direct.c	2009-09-09 18:39:10.902593154 +1000
+++ gdm-2.27.90-failsafe/daemon/gdm-session-direct.c	2009-09-09 21:04:10.641171722 +1000
@@ -2032,7 +2032,14 @@
         g_return_if_fail (impl->priv->is_running == FALSE);
 
         command = get_session_command (impl);
-        program = g_strdup_printf (GDMCONFDIR "/Xsession \"%s\"", command);
+
+        if (gdm_session_direct_is_failsafe(impl) == FALSE) {
+                program = g_strdup_printf (GDMCONFDIR "/Xsession \"%s\"", command);
+        } else {
+                /* Failsafe session: bypass the Xsession script */
+                program = g_strdup (command);
+        }
+
         g_free (command);
 
         setup_session_environment (impl);
@@ -2123,6 +2130,55 @@
         return g_strdup (session->priv->selected_user);
 }
 
+gboolean
+gdm_session_direct_is_failsafe (GdmSessionDirect *session_direct)
+{
+        GError     *error;
+        GKeyFile   *key_file;
+        gboolean    res;
+        gboolean    failsafe = FALSE;
+        char       *filename;
+        char       *full_path;
+
+        g_return_val_if_fail (session_direct != NULL, FALSE);
+        g_return_val_if_fail (GDM_IS_SESSION_DIRECT (session_direct), FALSE);
+
+        filename = g_strdup_printf ("%s.desktop", get_session_name (session_direct));
+
+        key_file = g_key_file_new ();
+        error = NULL;
+        res = g_key_file_load_from_dirs (key_file,
+                                         filename,
+                                         get_system_session_dirs (),
+                                         &full_path,
+                                         G_KEY_FILE_NONE,
+                                         &error);        
+        if (! res) {
+                g_debug ("GdmSessionDirect: File '%s' not found: %s", filename, error->message);
+                goto out;
+        }
+
+        error = NULL;
+        res = g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-GDM-FailSafe", NULL);
+        if (!res) {
+                failsafe =  FALSE;
+                goto out;
+        } else {
+                failsafe = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-GDM-FailSafe", &error);
+                if (error) {
+                        failsafe = FALSE;
+                        g_error_free (error);
+                        goto out;
+                } else if (failsafe == TRUE) {
+                        g_debug ("GdmSessionDirect: Session %s is tagged as failsafe", filename);
+                }
+        }
+
+out:
+        g_free (filename);
+        return failsafe;
+}
+
 static void
 gdm_session_direct_select_session (GdmSession *session,
                                    const char *text)
--- gdm-2.27.90/daemon/gdm-session-direct.h	2009-08-25 05:31:18.000000000 +1000
+++ gdm-2.27.90-failsafe/daemon/gdm-session-direct.h	2009-09-09 21:04:18.660554358 +1000
@@ -56,6 +56,7 @@
                                                                 gboolean    display_is_local) G_GNUC_MALLOC;
 
 char             * gdm_session_direct_get_username             (GdmSessionDirect     *session_direct);
+gboolean           gdm_session_direct_is_failsafe              (GdmSessionDirect     *session_direct);
 
 /* Exported methods */
 gboolean           gdm_session_direct_restart                  (GdmSessionDirect     *session_direct,
--- gdm-2.27.90/daemon/gdm-simple-slave.c	2009-09-09 18:39:10.855368061 +1000
+++ gdm-2.27.90-failsafe/daemon/gdm-simple-slave.c	2009-09-09 14:30:13.156128123 +1000
@@ -112,7 +112,11 @@
         username = gdm_session_direct_get_username (slave->priv->session);
         gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PreSession", username);
 
-        /* FIXME: should we do something here? */
+        /* FIXME: should we do something here?
+         * Note that error return status from PreSession script should
+         * be ignored in the case of a Failsafe session, which can be checked
+         * by calling: gdm_session_direct_is_failsafe(session)
+         */
 }
 
 static void
