Commit 815461a4 authored by Gaël Bonithon's avatar Gaël Bonithon
Browse files

panel: Fix xfce4-panel-CRITICAL when already running

`panel_dbus_service_is_exported()` is not the right test to know if an
instance is already running. Instead, let's follow the documentation of
`g_bus_own_name()`:
* if `panel_dbus_name_lost()` is called and `connection == NULL`, there
  is a dbus issue;
* if `panel_dbus_name_lost()` is called and `connection != NULL`, the
  name can't be acquired, which means that there is an already running
  instance if `G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT` is not set
  (which is currently the case for xfce4-panel);
* `application != NULL` if and only if `panel_dbus_name_acquired()` is
  called, if and only if `panel_dbus_name_lost()` is not called.
parent b0f88847
Pipeline #7526 passed with stages
in 4 minutes and 45 seconds
......@@ -204,7 +204,9 @@ panel_dbus_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_critical (_("Name %s lost on the message dbus, exiting."), name);
if (connection == NULL)
g_critical (_("Name %s lost on the message dbus, exiting."), name);
gtk_main_quit ();
}
......@@ -353,14 +355,6 @@ main (gint argc, gchar **argv)
/* start dbus service */
dbus_service = panel_dbus_service_get ();
if (!panel_dbus_service_is_exported (dbus_service))
{
/* quit without error if an instance is running */
succeed = TRUE;
g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance"));
goto dbus_return;
}
/* start session management */
sm_client = xfce_sm_client_get ();
......@@ -395,6 +389,11 @@ main (gint argc, gchar **argv)
g_object_unref (G_OBJECT (application));
}
else
{
/* quit without error if an instance is running */
g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance"));
}
g_object_unref (G_OBJECT (sm_client));
......
......@@ -92,9 +92,6 @@ struct _PanelDBusService
/* queue for remote-events */
GHashTable *remote_events;
/* whether the service is owner of the name */
guint is_exported : 1;
};
typedef struct
......@@ -132,27 +129,17 @@ panel_dbus_service_class_init (PanelDBusServiceClass *klass)
static void
panel_dbus_service_init (PanelDBusService *service)
{
GError *error = NULL;
GError *error = NULL;
service->is_exported = FALSE;
service->remote_events = NULL;
service->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (G_LIKELY (service->connection != NULL))
{
service->is_exported =
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service),
service->connection,
"/org/xfce/Panel",
&error);
if (error)
{
g_critical ("Failed to export panel D-BUS interface: %s", error->message);
g_error_free (error);
}
if (G_LIKELY (service->is_exported))
if (G_LIKELY (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (service),
service->connection,
"/org/xfce/Panel",
&error)))
{
g_signal_connect (service, "handle_add_new_item",
G_CALLBACK(panel_dbus_service_add_new_item), service);
......@@ -167,6 +154,11 @@ panel_dbus_service_init (PanelDBusService *service)
g_signal_connect (service, "handle_terminate",
G_CALLBACK(panel_dbus_service_terminate), service);
}
else
{
g_critical ("Failed to export panel D-BUS interface: %s", error->message);
g_error_free (error);
}
}
else
{
......@@ -481,15 +473,6 @@ panel_dbus_service_get (void)
gboolean
panel_dbus_service_is_exported (PanelDBusService *service)
{
panel_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE);
return service->is_exported;
}
void
panel_dbus_service_exit_panel (gboolean restart)
{
......
......@@ -38,8 +38,6 @@ GType panel_dbus_service_get_type (void) G_GNUC_CONST;
PanelDBusService *panel_dbus_service_get (void);
gboolean panel_dbus_service_is_exported (PanelDBusService *service);
void panel_dbus_service_exit_panel (gboolean restart);
gboolean panel_dbus_service_get_restart (void);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment