Skip to content

Commit 6c3ca38

Browse files
committed
session-quit: Use a unique dialog server address for each session.
This was preventing the logout dialog for subsequent users logged in, as it would attempt to connect to the original user's server (and be denied). A unique address will be generated at startup, and passed to the dialog when it is launched. Fixes linuxmint/cinnamon#12021
1 parent 066f1a6 commit 6c3ca38

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

cinnamon-session-quit/cinnamon-session-quit.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self):
6464
parser.add_argument("--no-prompt", dest="no_prompt", action='store_true',
6565
help=_("Don't prompt for user confirmation"))
6666
parser.add_argument("--sm-owned", action="store_true", help=argparse.SUPPRESS)
67+
parser.add_argument("--sm-bus-id", dest="bus_id", action="store", help=argparse.SUPPRESS)
6768
args = parser.parse_args()
6869

6970
self.dialog_response = ResponseCode.NONE
@@ -76,6 +77,11 @@ def __init__(self):
7677
self.no_prompt = args.no_prompt
7778
self.sm_owned = args.sm_owned
7879

80+
if self.sm_owned:
81+
self.bus_id = args.bus_id
82+
else:
83+
self.bus_id = None
84+
7985
self.proxy = None
8086
self.signal_handler_id = 0
8187

@@ -164,7 +170,7 @@ def setup_proxy(self):
164170

165171
try:
166172
connection = Gio.DBusConnection.new_for_address_sync(
167-
config.DBUS_ADDRESS,
173+
self.bus_id,
168174
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
169175
None, None
170176
)

cinnamon-session/csm-manager.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct CsmManagerPrivate
125125
GDBusServer *dialog_server;
126126
guint dialog_reg_id;
127127
CsmLogoutAction dialog_action;
128+
gchar *dialog_bus_address;
128129

129130
char *session_name;
130131
gboolean is_fallback_session : 1;
@@ -2917,7 +2918,10 @@ register_manager (CsmManager *manager)
29172918

29182919
// Set up private controller interface for dialog
29192920
gchar *guid = g_dbus_generate_guid ();
2920-
GDBusServer *server = g_dbus_server_new_sync (DBUS_ADDRESS,
2921+
manager->priv->dialog_bus_address = g_strdup_printf ("%s-%s", DBUS_ADDRESS, guid);
2922+
g_debug ("Dialog server address: %s", manager->priv->dialog_bus_address);
2923+
2924+
GDBusServer *server = g_dbus_server_new_sync (manager->priv->dialog_bus_address,
29212925
G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER,
29222926
guid,
29232927
NULL, NULL, &error);
@@ -3537,6 +3541,9 @@ csm_manager_dispose (GObject *object)
35373541
manager->priv->dialog_reg_id = 0;
35383542
g_dbus_node_info_unref (introspection_data);
35393543
g_dbus_server_stop (manager->priv->dialog_server);
3544+
g_object_unref (manager->priv->dialog_server);
3545+
g_object_unref (manager->priv->dialog_connection);
3546+
g_free (manager->priv->dialog_bus_address);
35403547
}
35413548

35423549
if (manager->priv->clients != NULL) {
@@ -3926,6 +3933,34 @@ on_dialog_exited (GObject *source,
39263933
g_clear_object (&dialog_cancellable);
39273934
}
39283935

3936+
static void
3937+
on_dialog_read (GObject *source,
3938+
GAsyncResult *result,
3939+
gpointer user_data)
3940+
{
3941+
GInputStream *stream = G_INPUT_STREAM (source);
3942+
3943+
g_debug ("Session quit dialog read output");
3944+
3945+
gssize read = g_input_stream_read_finish (stream, result, NULL);
3946+
if (read > 0) {
3947+
g_debug ("Session quit dialog (self-owned) output: %.*s", (gint) read, (gchar *) user_data);
3948+
} else {
3949+
g_debug ("Session quit dialog (self-owned) stdout closed");
3950+
g_free (user_data);
3951+
g_input_stream_close (stream, NULL, NULL);
3952+
return;
3953+
}
3954+
3955+
g_input_stream_read_async (stream,
3956+
user_data,
3957+
1024,
3958+
G_PRIORITY_DEFAULT,
3959+
NULL,
3960+
(GAsyncReadyCallback) on_dialog_read,
3961+
user_data);
3962+
}
3963+
39293964
static void
39303965
terminate_dialog (void)
39313966
{
@@ -3959,12 +3994,13 @@ launch_dialog (CsmManager *manager, const gchar *flag)
39593994
const gchar *argv[] = {
39603995
"cinnamon-session-quit",
39613996
"--sm-owned",
3997+
"--sm-bus-id", manager->priv->dialog_bus_address,
39623998
flag,
39633999
NULL
39644000
};
39654001

39664002
error = NULL;
3967-
dialog_process = g_subprocess_newv (argv, G_SUBPROCESS_FLAGS_NONE, &error);
4003+
dialog_process = g_subprocess_newv (argv, G_SUBPROCESS_FLAGS_STDERR_MERGE | G_SUBPROCESS_FLAGS_STDOUT_PIPE, &error);
39684004

39694005
if (dialog_process == NULL) {
39704006
if (error != NULL) {
@@ -3974,6 +4010,16 @@ launch_dialog (CsmManager *manager, const gchar *flag)
39744010
}
39754011
}
39764012

4013+
GInputStream *stdout = g_subprocess_get_stdout_pipe (dialog_process);
4014+
guint8 *buffer = g_malloc (1024);
4015+
g_input_stream_read_async (G_INPUT_STREAM (stdout),
4016+
buffer,
4017+
1024,
4018+
G_PRIORITY_DEFAULT,
4019+
NULL,
4020+
(GAsyncReadyCallback) on_dialog_read,
4021+
buffer);
4022+
39774023
dialog_cancellable = g_cancellable_new ();
39784024

39794025
g_subprocess_wait_async (dialog_process,

0 commit comments

Comments
 (0)