Skip to content

Commit 409d9fc

Browse files
vuntzvkareh
authored andcommitted
gsm: Disconnect all dbus clients when dbus is disconnected
When we receive the Disconnected signal from dbus on the session bus, then we know we won't be able to talk to dbus clients anymore, so mark them as disconnected. Also, do not restart them even if they're supposed to be autorestarted, as we won't be able to track them. At this point, the session is kind of hosed. We could possibly decide to simply leave, but we don't do it in case it's a user session and there's unsaved data. This helps a lot in the case of the gdm greeter, see https://bugzilla.gnome.org/show_bug.cgi?id=658481 Adapted from https://gitlab.gnome.org/GNOME/gnome-session/commit/ae8fa537
1 parent 0f4afbb commit 409d9fc

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

mate-session/gsm-manager.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ typedef struct {
146146

147147
DBusGProxy *bus_proxy;
148148
DBusGConnection *connection;
149+
gboolean dbus_disconnected : 1;
149150
} GsmManagerPrivate;
150151

151152
enum {
@@ -1798,6 +1799,12 @@ _disconnect_client (GsmManager *manager,
17981799
"phase");
17991800
}
18001801

1802+
if (priv->dbus_disconnected && GSM_IS_DBUS_CLIENT (client)) {
1803+
g_debug ("GsmManager: dbus disconnected, not restarting application");
1804+
goto out;
1805+
}
1806+
1807+
18011808
if (app == NULL) {
18021809
g_debug ("GsmManager: unable to find application for client - not restarting");
18031810
goto out;
@@ -1852,6 +1859,12 @@ _disconnect_dbus_client (const char *id,
18521859
return FALSE;
18531860
}
18541861

1862+
/* If no service name, then we simply disconnect all clients */
1863+
if (!data->service_name) {
1864+
_disconnect_client (data->manager, client);
1865+
return TRUE;
1866+
}
1867+
18551868
name = gsm_dbus_client_get_bus_name (GSM_DBUS_CLIENT (client));
18561869
if (IS_STRING_EMPTY (name)) {
18571870
return FALSE;
@@ -1865,6 +1878,15 @@ _disconnect_dbus_client (const char *id,
18651878
return FALSE;
18661879
}
18671880

1881+
/**
1882+
* remove_clients_for_connection:
1883+
* @manager: a #GsmManager
1884+
* @service_name: a service name
1885+
*
1886+
* Disconnects clients that own @service_name.
1887+
*
1888+
* If @service_name is NULL, then disconnects all clients for the connection.
1889+
*/
18681890
static void
18691891
remove_clients_for_connection (GsmManager *manager,
18701892
const char *service_name)
@@ -1952,11 +1974,36 @@ bus_name_owner_changed (DBusGProxy *bus_proxy,
19521974
}
19531975
}
19541976

1977+
static DBusHandlerResult
1978+
gsm_manager_bus_filter (DBusConnection *connection,
1979+
DBusMessage *message,
1980+
void *user_data)
1981+
{
1982+
GsmManager *manager;
1983+
GsmManagerPrivate *priv;
1984+
1985+
manager = GSM_MANAGER (user_data);
1986+
priv = gsm_manager_get_instance_private (manager);
1987+
1988+
if (dbus_message_is_signal (message,
1989+
DBUS_INTERFACE_LOCAL, "Disconnected") &&
1990+
strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
1991+
g_debug ("GsmManager: dbus disconnected; disconnecting dbus clients...");
1992+
priv->dbus_disconnected = TRUE;
1993+
remove_clients_for_connection (manager, NULL);
1994+
/* let other filters get this disconnected signal, so that they
1995+
* can handle it too */
1996+
}
1997+
1998+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1999+
}
2000+
19552001
static gboolean
19562002
register_manager (GsmManager *manager)
19572003
{
19582004
GError *error = NULL;
19592005
GsmManagerPrivate *priv;
2006+
DBusConnection *connection;
19602007

19612008
error = NULL;
19622009
priv = gsm_manager_get_instance_private (manager);
@@ -1970,6 +2017,12 @@ register_manager (GsmManager *manager)
19702017
exit (1);
19712018
}
19722019

2020+
connection = dbus_g_connection_get_connection (priv->connection);
2021+
dbus_connection_add_filter (connection,
2022+
gsm_manager_bus_filter,
2023+
manager, NULL);
2024+
priv->dbus_disconnected = FALSE;
2025+
19732026
priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection,
19742027
DBUS_SERVICE_DBUS,
19752028
DBUS_PATH_DBUS,

0 commit comments

Comments
 (0)