[gdm/multi-stack: 5/46] Store multiple conversations in the session
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/multi-stack: 5/46] Store multiple conversations in the session
- Date: Fri, 26 Mar 2010 13:34:02 +0000 (UTC)
commit dbe4432be68809b93180fbb22432049ac6f15cd3
Author: Ray Strode <rstrode redhat com>
Date: Fri Jan 16 15:18:31 2009 -0500
Store multiple conversations in the session
We keep multiple conversations in the session now, keyed off of
PAM service is at the other end. Much of the guts still
only operate on the first conversation added though.
daemon/gdm-session-direct.c | 123 +++++++++++++++++++++++++++++++++++++------
1 files changed, 106 insertions(+), 17 deletions(-)
---
diff --git a/daemon/gdm-session-direct.c b/daemon/gdm-session-direct.c
index abc3c9d..5281b2b 100644
--- a/daemon/gdm-session-direct.c
+++ b/daemon/gdm-session-direct.c
@@ -89,6 +89,7 @@ struct _GdmSessionDirectPrivate
char *user_x11_authority_file;
GdmSessionConversation *conversation;
+ GHashTable *conversations;
GdmSessionWorkerJob *job;
GPid session_pid;
@@ -1549,6 +1550,42 @@ allow_user_function (DBusConnection *connection,
return FALSE;
}
+static GdmSessionConversation *
+find_conversation_by_name (GdmSessionDirect *session,
+ const char *service_name)
+{
+ GdmSessionConversation *conversation;
+
+ conversation = g_hash_table_lookup (session->priv->conversations, service_name);
+
+ if (conversation == NULL) {
+ g_warning ("Tried to look up non-existant conversation");
+ }
+
+ return conversation;
+}
+
+static GdmSessionConversation *
+find_conversation_by_pid (GdmSessionDirect *session,
+ GPid pid)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init (&iter, session->priv->conversations);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ GdmSessionConversation *conversation;
+
+ conversation = (GdmSessionConversation *) value;
+
+ if (conversation->worker_pid == pid) {
+ return conversation;
+ }
+ }
+
+ return NULL;
+}
+
static void
handle_connection (DBusServer *server,
DBusConnection *new_connection,
@@ -1556,10 +1593,22 @@ handle_connection (DBusServer *server,
{
GdmSessionDirect *session = GDM_SESSION_DIRECT (user_data);
GdmSessionConversation *conversation;
+ gulong pid;
g_debug ("GdmSessionDirect: Handing new connection");
- conversation = session->priv->conversation;
+ if (!dbus_connection_get_unix_process_id (new_connection, &pid)) {
+ g_warning ("Unable to read pid on new worker connection");
+ return;
+ }
+
+ conversation = find_conversation_by_pid (session, (GPid) pid);
+
+ if (conversation == NULL) {
+ g_warning ("New worker connection is from unknown source");
+ return;
+ }
+
if (conversation->worker_connection == NULL) {
DBusObjectPathVTable vtable = { &session_unregister_handler,
&session_message_handler,
@@ -1632,6 +1681,17 @@ setup_server (GdmSessionDirect *session)
}
static void
+free_conversation (GdmSessionConversation *conversation)
+{
+ if (conversation->job != NULL) {
+ g_warning ("Freeing conversation with active job");
+ }
+
+ g_free (conversation->service_name);
+ g_free (conversation);
+}
+
+static void
gdm_session_direct_init (GdmSessionDirect *session)
{
session->priv = G_TYPE_INSTANCE_GET_PRIVATE (session,
@@ -1655,6 +1715,11 @@ gdm_session_direct_init (GdmSessionDirect *session)
G_CALLBACK (on_session_exited),
NULL);
+ session->priv->conversations = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify)
+ free_conversation);
session->priv->environment = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
@@ -1754,17 +1819,15 @@ stop_conversation (GdmSessionConversation *conversation)
G_CALLBACK (worker_died),
conversation);
- cancel_pending_query (conversation);
-
if (conversation->worker_connection != NULL) {
dbus_connection_close (conversation->worker_connection);
conversation->worker_connection = NULL;
}
gdm_session_worker_job_stop (conversation->job);
+
g_object_unref (conversation->job);
- g_free (conversation->service_name);
- g_free (conversation);
+ conversation->job = NULL;
}
static void
@@ -1772,12 +1835,20 @@ gdm_session_direct_start_conversation (GdmSession *session,
const char *service_name)
{
GdmSessionDirect *impl = GDM_SESSION_DIRECT (session);
+ GdmSessionConversation *conversation;
g_return_if_fail (session != NULL);
g_debug ("GdmSessionDirect: starting conversation");
- impl->priv->conversation = start_conversation (impl, service_name);
+ conversation = start_conversation (impl, service_name);
+
+ g_hash_table_insert (impl->priv->conversations,
+ g_strdup (service_name), conversation);
+
+ if (impl->priv->conversation != NULL) {
+ impl->priv->conversation = conversation;
+ }
}
static void
@@ -1828,8 +1899,8 @@ send_setup (GdmSessionDirect *session,
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &display_hostname);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &display_x11_authority_file);
- conversation = session->priv->conversation;
- if (! send_dbus_message (conversation, message)) {
+ conversation = find_conversation_by_name (session, service_name);
+ if (conversation != NULL && ! send_dbus_message (conversation, message)) {
g_debug ("GdmSessionDirect: Could not send %s signal", "Setup");
}
@@ -1891,8 +1962,8 @@ send_setup_for_user (GdmSessionDirect *session,
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &display_x11_authority_file);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &selected_user);
- conversation = session->priv->conversation;
- if (! send_dbus_message (conversation, message)) {
+ conversation = find_conversation_by_name (session, service_name);
+ if (conversation != NULL && ! send_dbus_message (conversation, message)) {
g_debug ("GdmSessionDirect: Could not send %s signal", "SetupForUser");
}
@@ -1906,8 +1977,6 @@ gdm_session_direct_setup (GdmSession *session,
GdmSessionDirect *impl = GDM_SESSION_DIRECT (session);
g_return_if_fail (session != NULL);
- g_return_if_fail (impl->priv->conversation != NULL);
- g_return_if_fail (dbus_connection_get_is_connected (impl->priv->conversation->worker_connection));
send_setup (impl, service_name);
gdm_session_direct_defaults_changed (impl);
@@ -1921,8 +1990,6 @@ gdm_session_direct_setup_for_user (GdmSession *session,
GdmSessionDirect *impl = GDM_SESSION_DIRECT (session);
g_return_if_fail (session != NULL);
- g_return_if_fail (impl->priv->conversation != NULL);
- g_return_if_fail (dbus_connection_get_is_connected (impl->priv->conversation->worker_connection));
g_return_if_fail (username != NULL);
gdm_session_direct_select_user (session, username);
@@ -2170,6 +2237,28 @@ gdm_session_direct_start_session (GdmSession *session)
}
static void
+stop_all_conversations (GdmSessionDirect *session)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ if (session->priv->conversations == NULL) {
+ return;
+ }
+
+ g_hash_table_iter_init (&iter, session->priv->conversations);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ GdmSessionConversation *conversation;
+
+ conversation = (GdmSessionConversation *) value;
+
+ stop_conversation (conversation);
+ }
+
+ g_hash_table_remove_all (session->priv->conversations);
+}
+
+static void
gdm_session_direct_close (GdmSession *session)
{
GdmSessionDirect *impl = GDM_SESSION_DIRECT (session);
@@ -2186,6 +2275,8 @@ gdm_session_direct_close (GdmSession *session)
impl->priv->display_device);
}
+ stop_all_conversations (impl);
+
g_free (impl->priv->selected_user);
impl->priv->selected_user = NULL;
@@ -2233,11 +2324,9 @@ gdm_session_direct_answer_query (GdmSession *session,
static void
gdm_session_direct_cancel (GdmSession *session)
{
- GdmSessionDirect *impl = GDM_SESSION_DIRECT (session);
-
g_return_if_fail (session != NULL);
- cancel_pending_query (impl->priv->conversation);
+ stop_all_conversations (GDM_SESSION_DIRECT (session));
}
char *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]