Skip to content

Commit

Permalink
mate-session-save: try org.mate.SessionManager if org.gnome fails
Browse files Browse the repository at this point in the history
fixes #103
  • Loading branch information
monsta committed Oct 21, 2015
1 parent c1b21ea commit 9582afb
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions tools/mate-session-save.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define GSM_PATH_DBUS "/org/gnome/SessionManager"
#define GSM_INTERFACE_DBUS "org.gnome.SessionManager"

#define GSM_SERVICE_DBUS_OLD "org.mate.SessionManager"
#define GSM_PATH_DBUS_OLD "/org/mate/SessionManager"
#define GSM_INTERFACE_DBUS_OLD "org.mate.SessionManager"

enum {
GSM_LOGOUT_MODE_NORMAL = 0,
GSM_LOGOUT_MODE_NO_CONFIRMATION,
Expand Down Expand Up @@ -105,6 +109,20 @@ static DBusGConnection* get_session_bus(void)
return bus;
}

static DBusGProxy* create_proxy(DBusGConnection *connection, const char *name, const char *path, const char *iface)
{
GError* error = NULL;
DBusGProxy* proxy = dbus_g_proxy_new_for_name_owner(connection, name, path, iface, &error);

if (proxy == NULL)
{
g_warning("Couldn't create DBus proxy: %s", error->message);
g_error_free(error);
}

return proxy;
}

static DBusGProxy* get_sm_proxy(void)
{
DBusGConnection* connection;
Expand All @@ -118,12 +136,20 @@ static DBusGProxy* get_sm_proxy(void)
return NULL;
}

sm_proxy = dbus_g_proxy_new_for_name(connection, GSM_SERVICE_DBUS, GSM_PATH_DBUS, GSM_INTERFACE_DBUS);
sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS, GSM_PATH_DBUS, GSM_INTERFACE_DBUS);

if (sm_proxy == NULL)
{
display_error(_("Could not connect to the session manager"));
return NULL;
/* Try the old name - for the case when we've just upgraded from 1.10
* so the old m-s-m is currently running */
sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS_OLD, GSM_PATH_DBUS_OLD, GSM_INTERFACE_DBUS_OLD);

if (sm_proxy == NULL)
{
/* Okay, it wasn't the upgrade case, so now we can give up. */
display_error(_("Could not connect to the session manager"));
return NULL;
}
}

return sm_proxy;
Expand Down

0 comments on commit 9582afb

Please sign in to comment.