[Xfce4-commits] <xfce4-appfinder:nick/xfrun4-merge> Use --disable-server to avoid dbus and daemonize.
Nick Schermer
noreply at xfce.org
Mon Jun 13 21:12:01 CEST 2011
Updating branch refs/heads/nick/xfrun4-merge
to f8c3d3ecb578343e8e222eb299d40a81a7d360c6 (commit)
from fabc069757b2d975eede1fadc835a78d3982ab16 (commit)
commit f8c3d3ecb578343e8e222eb299d40a81a7d360c6
Author: Nick Schermer <nick at xfce.org>
Date: Mon Jun 13 21:06:58 2011 +0200
Use --disable-server to avoid dbus and daemonize.
Better usage for a standalone appfinder. Also move
D-Bus service in its own function.
src/main.c | 172 ++++++++++++++++++++++++++++++++++--------------------------
1 files changed, 97 insertions(+), 75 deletions(-)
diff --git a/src/main.c b/src/main.c
index ce590f4..64b0d13 100644
--- a/src/main.c
+++ b/src/main.c
@@ -58,7 +58,7 @@ static gboolean opt_version = FALSE;
static gboolean opt_replace = FALSE;
static gboolean opt_quit = FALSE;
static gchar *opt_filename = NULL;
-static gboolean opt_no_daemon = FALSE;
+static gboolean opt_disable_server = FALSE;
static GSList *windows = NULL;
static gboolean service_owner = FALSE;
@@ -70,7 +70,7 @@ static GOptionEntry option_entries[] =
{ "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL },
{ "replace", 'r', 0, G_OPTION_ARG_NONE, &opt_replace, N_("Replace the existing service"), NULL },
{ "quit", 'q', 0, G_OPTION_ARG_NONE, &opt_quit, N_("Quit all instances"), NULL },
- { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &opt_no_daemon, N_("Do not fork to the background"), NULL },
+ { "disable-server", 0, 0, G_OPTION_ARG_NONE, &opt_disable_server, N_("Do not try to use or become a D-Bus service"), NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME, &opt_filename, NULL, NULL },
{ NULL }
};
@@ -299,68 +299,14 @@ appfinder_daemonize (void)
-gint
-main (gint argc, gchar **argv)
+static DBusConnection *
+appfinder_dbus_service (const gchar *startup_id)
{
- GError *error = NULL;
- const gchar *desktop;
+ DBusError derror;
DBusConnection *dbus_connection;
guint dbus_flags;
DBusObjectPathVTable vtable = { NULL, appfinder_dbus_message, NULL, };
gint result;
- const gchar *startup_id;
- DBusError derror;
- GSList *windows_destroy;
-
- /* set translation domain */
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
-
-#ifdef G_ENABLE_DEBUG
- /* do NOT remove this line for now, If something doesn't work,
- * fix your code instead! */
- g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
-#endif
-
- if (!g_thread_supported ())
- g_thread_init (NULL);
-
- /* get the startup notification id */
- startup_id = g_getenv ("DESKTOP_STARTUP_ID");
-
- if (!gtk_init_with_args (&argc, &argv, _("[MENUFILE]"), option_entries, GETTEXT_PACKAGE, &error))
- {
- g_printerr ("%s: %s.\n", PACKAGE_NAME, error->message);
- g_printerr (_("Type \"%s --help\" for usage."), PACKAGE_NAME);
- g_printerr ("\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) 2004-2010");
- g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
- g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
- g_print ("\n");
-
- return EXIT_SUCCESS;
- }
-
- if (opt_quit)
- return appfinder_dbus_quit ();
-
- /* if the value is unset, fallback to XFCE, if the
- * value is empty, allow all applications in the menu */
- desktop = g_getenv ("XDG_CURRENT_DESKTOP");
- if (G_LIKELY (desktop == NULL))
- desktop = "XFCE";
- else if (*desktop == '\0')
- desktop = NULL;
- garcon_set_environment (desktop);
-
- xfconf_init (NULL);
/* become the serivce owner or ask the current owner to spawn an instance */
dbus_error_init (&derror);
@@ -391,23 +337,21 @@ main (gint argc, gchar **argv)
/* successfully registered the service */
service_owner = TRUE;
- if (!opt_no_daemon)
+ /* fork to the background */
+ if (appfinder_daemonize () == -1)
{
- /* fork to the background */
- if (appfinder_daemonize () == -1)
- {
- xfce_message_dialog (NULL, _("Application Finder"),
- GTK_STOCK_DIALOG_ERROR,
- _("Unable to daemonize the process"),
- g_strerror (errno),
- GTK_STOCK_QUIT, GTK_RESPONSE_ACCEPT,
- NULL);
-
- return EXIT_FAILURE;
- }
-
- APPFINDER_DEBUG ("daemonized the process");
+ xfce_message_dialog (NULL, _("Application Finder"),
+ GTK_STOCK_DIALOG_ERROR,
+ _("Unable to daemonize the process"),
+ g_strerror (errno),
+ GTK_STOCK_QUIT, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ _exit (EXIT_FAILURE);
}
+
+ APPFINDER_DEBUG ("daemonized the process");
+
}
else
{
@@ -420,13 +364,16 @@ main (gint argc, gchar **argv)
{
/* successfully opened a window in the other instance */
dbus_connection_unref (dbus_connection);
- return EXIT_SUCCESS;
+ _exit (EXIT_SUCCESS);
}
}
else
{
g_warning ("Unable to request D-Bus name: %s", derror.message);
dbus_error_free (&derror);
+
+ dbus_connection_unref (dbus_connection);
+ dbus_connection = NULL;
}
}
else
@@ -435,6 +382,81 @@ main (gint argc, gchar **argv)
dbus_error_free (&derror);
}
+ return dbus_connection;
+}
+
+
+
+gint
+main (gint argc, gchar **argv)
+{
+ GError *error = NULL;
+ const gchar *desktop;
+ DBusConnection *dbus_connection = NULL;
+ const gchar *startup_id;
+ GSList *windows_destroy;
+
+ /* set translation domain */
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+#ifdef G_ENABLE_DEBUG
+ /* do NOT remove this line for now, If something doesn't work,
+ * fix your code instead! */
+ g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
+#endif
+
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+ /* get the startup notification id */
+ startup_id = g_getenv ("DESKTOP_STARTUP_ID");
+
+ if (!gtk_init_with_args (&argc, &argv, _("[MENUFILE]"), option_entries, GETTEXT_PACKAGE, &error))
+ {
+ g_printerr ("%s: %s.\n", PACKAGE_NAME, error->message);
+ g_printerr (_("Type \"%s --help\" for usage."), PACKAGE_NAME);
+ g_printerr ("\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) 2004-2010");
+ g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
+ g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
+ g_print ("\n");
+
+ return EXIT_SUCCESS;
+ }
+
+ if (opt_quit)
+ return appfinder_dbus_quit ();
+
+ /* become the serivce owner or ask the current
+ * owner to spawn an instance */
+ if (G_LIKELY (!opt_disable_server))
+ dbus_connection = appfinder_dbus_service (startup_id);
+
+ /* if the value is unset, fallback to XFCE, if the
+ * value is empty, allow all applications in the menu */
+ desktop = g_getenv ("XDG_CURRENT_DESKTOP");
+ if (G_LIKELY (desktop == NULL))
+ desktop = "XFCE";
+ else if (*desktop == '\0')
+ desktop = NULL;
+ garcon_set_environment (desktop);
+
+ if (!xfconf_init (&error))
+ {
+ g_critical ("Failed to initialized xfconf: %s", error->message);
+ g_error_free (error);
+
+ return EXIT_FAILURE;
+ }
+
/* create initial window */
appfinder_window_new (NULL, opt_expanded, opt_filename);
More information about the Xfce4-commits
mailing list