[Xfce4-commits] <xfce4-session:nick/shutdown-cleanup> Let xfce4-session handle the dbus-launch checking.

Nick Schermer noreply at xfce.org
Sat Feb 25 11:04:02 CET 2012


Updating branch refs/heads/nick/shutdown-cleanup
         to d0fd751f54c8b3231aecfb5ac367f6444206ad4f (commit)
       from b6c8ca513166fd96229c8ba945fa43035c2df407 (commit)

commit d0fd751f54c8b3231aecfb5ac367f6444206ad4f
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Feb 25 10:30:12 2012 +0100

    Let xfce4-session handle the dbus-launch checking.
    
    This makes it easier to start a fully working session
    with only xfce4-session.

 scripts/xinitrc.in.in |   26 ++++++----------
 xfce4-session/main.c  |   75 ++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 69 insertions(+), 32 deletions(-)

diff --git a/scripts/xinitrc.in.in b/scripts/xinitrc.in.in
index a5afc24..2bfaa45 100755
--- a/scripts/xinitrc.in.in
+++ b/scripts/xinitrc.in.in
@@ -56,11 +56,6 @@ export GLADE_CATALOG_PATH
 export GLADE_PIXMAP_PATH
 export GLADE_MODULE_PATH
 
-# Export GTK_PATH so that GTK+ can find the Xfce theme engine
-# https://bugzilla.xfce.org/show_bug.cgi?id=7483
-#GTK_PATH="$GTK_PATH:@_libdir_@/gtk-2.0"
-#export GTK_PATH
-
 # For now, start with an empty list
 XRESOURCES=""
 
@@ -89,17 +84,6 @@ cat /dev/null $XRESOURCES | xrdb -nocpp -merge -
 # load local modmap
 test -r $HOME/.Xmodmap && xmodmap $HOME/.Xmodmap
 
-# Use dbus-launch if installed.
-if test x"$DBUS_SESSION_BUS_ADDRESS" = x""; then
-    if which dbus-launch >/dev/null 2>&1; then
-		eval `dbus-launch --sh-syntax --exit-with-session`
-        # some older versions of dbus don't export the var properly
-        export DBUS_SESSION_BUS_ADDRESS
-    else
-        echo "Could not find dbus-launch; Xfce will not work properly" >&2
-	fi
-fi
-
 # Run xfce4-session if installed
 if which xfce4-session >/dev/null 2>&1; then
     xfce4-session
@@ -120,6 +104,16 @@ fi
 
 ##################
 
+# Use dbus-launch if installed.
+if test x"$DBUS_SESSION_BUS_ADDRESS" = x""; then
+  if which dbus-launch >/dev/null 2>&1; then
+    eval `dbus-launch --sh-syntax --exit-with-session`
+    # some older versions of dbus don't export the var properly
+    export DBUS_SESSION_BUS_ADDRESS
+  else
+    echo "Could not find dbus-launch; Xfce will not work properly" >&2
+    fi
+fi
 
 # this is only necessary when running w/o xfce4-session
 xsetroot -solid black -cursor_name watch
diff --git a/xfce4-session/main.c b/xfce4-session/main.c
index 01ef93e..0ae376a 100644
--- a/xfce4-session/main.c
+++ b/xfce4-session/main.c
@@ -192,6 +192,46 @@ xfsm_dbus_cleanup (void)
                          "org.xfce.SessionManager", NULL);
 }
 
+static gboolean
+xfsm_dbus_require_session (gint argc, gchar **argv)
+{
+  gchar **new_argv;
+  gchar  *path;
+  gint    i;
+  guint   m = 0;
+
+  if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") != NULL)
+    return TRUE;
+
+  path = g_find_program_in_path ("dbus-launch");
+  if (path == NULL)
+    {
+      g_critical ("dbus-launch not found, the desktop will not work properly!");
+      return TRUE;
+    }
+
+  /* avoid rondtrips */
+  g_assert (!g_str_has_prefix (*argv, "dbus-launch"));
+
+  new_argv = g_new0 (gchar *, argc + 4);
+  new_argv[m++] = path;
+  new_argv[m++] = "--sh-syntax";
+  new_argv[m++] = "--exit-with-session";
+
+  for (i = 0; i < argc; i++)
+    new_argv[m++] = argv[i];
+
+  if (!execvp ("dbus-launch", new_argv))
+    {
+      g_critical ("Could not spawn %s: %s", path, g_strerror (errno));
+    }
+
+  g_free (path);
+  g_free (new_argv);
+
+  return FALSE;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -203,36 +243,39 @@ main (int argc, char **argv)
   XfsmShutdown     *shutdown_helper;
   gboolean          succeed = TRUE;
 
+  if (!xfsm_dbus_require_session (argc, argv))
+    return EXIT_SUCCESS;
+
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
   /* install required signal handlers */
   signal (SIGPIPE, SIG_IGN);
 
-  if (!gtk_init_with_args (&argc, &argv, "", option_entries, GETTEXT_PACKAGE, &error)) {
-    g_error ("%s", error->message);
-    g_error_free (error);
-    return EXIT_FAILURE;
-  }
+  if (!gtk_init_with_args (&argc, &argv, "", option_entries, GETTEXT_PACKAGE, &error))
+    {
+      g_print ("%s: %s.\n", G_LOG_DOMAIN, error->message);
+      g_print (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
+      g_print ("\n");
+      g_error_free (error);
+      return EXIT_FAILURE;
+    }
 
   if (opt_version)
     {
-      g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ());
-      g_print ("%s\n", "Copyright (c) 2003-2011");
+      g_print ("%s %s (Xfce %s)\n\n", G_LOG_DOMAIN, PACKAGE_VERSION, xfce_version_string ());
+      g_print ("%s\n", "Copyright (c) 2003-2012");
       g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
-      g_print ("%s\n\n", _("Written by Benedikt Meurer <benny at xfce.org>."));
-      g_print (_("Built with Gtk+-%d.%d.%d, running with Gtk+-%d.%d.%d"),
-               GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
-               gtk_major_version, gtk_minor_version, gtk_micro_version);
-      g_print ("\n");
       g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
       g_print ("\n");
+
       return EXIT_SUCCESS;
     }
 
-  if (G_UNLIKELY (!xfconf_init (&error))) {
-    xfce_dialog_show_error (NULL, error, _("Unable to contact settings server"));
-    g_error_free (error);
-  }
+  if (!xfconf_init (&error))
+    {
+      xfce_dialog_show_error (NULL, error, _("Unable to contact settings server"));
+      g_error_free (error);
+    }
 
   /* fake a client id for the manager, so the legacy management does not
    * recognize us to be a session client.


More information about the Xfce4-commits mailing list