[Xfce4-commits] [xfce/xfce4-power-manager] 04/05: Fork before gtk/dbus init

noreply at xfce.org noreply at xfce.org
Thu Jun 26 18:50:20 CEST 2014


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit 216a5b750ccbe9fda98e0456a607230cd8c52303
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Thu Jun 26 19:46:46 2014 +0300

    Fork before gtk/dbus init
    
    https://mail.xfce.org/pipermail/xfce4-dev/2014-May/030715.html
    has the rational for the change.
---
 src/xfpm-main.c |   50 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index c54307b..e73b97d 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -251,6 +251,7 @@ int main (int argc, char **argv)
     DBusGConnection *bus;
     GError *error = NULL;
     DBusGProxy *proxy;
+    GOptionContext *octx;
      
     gboolean run        = FALSE;
     gboolean quit       = FALSE;
@@ -278,18 +279,46 @@ int main (int argc, char **argv)
 
 #if !GLIB_CHECK_VERSION (2, 32, 0)
     if ( !g_thread_supported () )
-	g_thread_init (NULL);
+        g_thread_init (NULL);
 #endif
 
+    /* Parse the options */
+    octx = g_option_context_new("");
+    g_option_context_set_ignore_unknown_options(octx, TRUE);
+    g_option_context_add_main_entries(octx, option_entries, NULL);
+    g_option_context_add_group(octx, xfce_sm_client_get_option_group(argc, argv));
+    /* We can't add the following command because it will invoke gtk_init
+       before we have a chance to fork.
+       g_option_context_add_group(octx, gtk_get_option_group(TRUE));
+     */
+
+    if(!g_option_context_parse(octx, &argc, &argv, &error)) {
+        g_printerr(_("Failed to parse arguments: %s\n"), error->message);
+        g_option_context_free(octx);
+        g_error_free(error);
+
+        return EXIT_FAILURE;
+    }
+
+    g_option_context_free(octx);
+
+    /* Fork if needed */
+    if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) )
+    {
+        g_critical ("Could not daemonize");
+    }
+
+
+    /* Initialize */
     dbus_g_thread_init ();
 
     xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
-    
+
     g_set_application_name (PACKAGE_NAME);
-    
-    if (!gtk_init_with_args (&argc, &argv, (gchar *)"", option_entries, (gchar *)PACKAGE, &error)) 
+
+    if (!gtk_init_check (&argc, &argv))
     {
-        if (G_LIKELY (error)) 
+        if (G_LIKELY (error))
         {
             g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
             g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
@@ -299,22 +328,17 @@ int main (int argc, char **argv)
         else
         {
             g_error ("Unable to open display.");
-	}
+        }
 
         return EXIT_FAILURE;
     }
-    
+
     if ( version )    
     {
-	show_version ();
+        show_version ();
     }
     
     xfpm_debug_init (debug);
-
-    if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) )
-    {
-	g_critical ("Could not daemonize");
-    }
     
     bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
             

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list