login1_active_session_changed_cb (Login1Seat *login1_seat, const gchar *login1_session_id)
{
g_debug ("Seat %s changes active session to %s", login1_seat_get_id (login1_seat), login1_session_id);
+
+ Seat *seat;
+ seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
+
+ if (seat)
+ {
+ Session *active_session;
+ active_session = seat_get_expected_active_session (seat);
+
+ if (g_strcmp0 (login1_session_id, session_get_login1_session_id (active_session)) == 0)
+ {
+ // Session is already active
+ g_debug ("Session %s is already active", login1_session_id);
+ return;
+ }
+
+ active_session = seat_find_session_by_login1_id (seat, login1_session_id);
+ if (active_session != NULL)
+ {
+ g_debug ("Activating session %s", login1_session_id);
+ seat_set_externally_activated_session (seat, active_session);
+ return;
+
+ }
+ }
}
static gboolean
return seat->priv->next_session;
}
+/**
+ * Obtains the active session which lightdm expects to be active.
+ *
+ * This function is different from seat_get_active_session() in that the
+ * later (in the case of xlocal seats) dynamically finds the session that is
+ * really active (based on the active VT), whereas this function returns the
+ * session that lightdm activated last by itself, which may not be the actual
+ * active session (i.e. VT changes).
+ */
+Session *
+seat_get_expected_active_session (Seat *seat)
+{
+ g_return_val_if_fail (seat != NULL, NULL);
+ return seat->priv->active_session;
+}
+
+/**
+ * Sets the active session which lightdm expects to be active.
+ *
+ * This function is different from seat_set_active_session() in that the
+ * later performs an actual session activation, whereas this function just
+ * updates the active session after the session has been activated by some
+ * means external to lightdm (i.e. VT changes).
+ */
+void
+seat_set_externally_activated_session (Seat *seat, Session *session)
+{
+ g_return_if_fail (seat != NULL);
+ if (seat->priv->active_session)
+ g_object_unref (seat->priv->active_session);
+ seat->priv->active_session = g_object_ref (session);
+}
+
+Session *
+seat_find_session_by_login1_id (Seat *seat, const gchar *login1_session_id)
+{
+ GList *session_link;
+
+ for (session_link = seat->priv->sessions; session_link; session_link = session_link->next)
+ {
+ Session *session = session_link->data;
+ if (g_strcmp0 (login1_session_id, session_get_login1_session_id (session)) == 0)
+ return session;
+ }
+
+ return NULL;
+}
+
gboolean
seat_get_can_switch (Seat *seat)
{
Session *seat_get_next_session (Seat *seat);
+void seat_set_externally_activated_session (Seat *seat, Session *session);
+
+Session *seat_get_expected_active_session (Seat *seat);
+
+Session *seat_find_session_by_login1_id (Seat *seat, const gchar *login1_session_id);
+
gboolean seat_get_can_switch (Seat *seat);
gboolean seat_get_allow_guest (Seat *seat);
return session->priv->username;
}
+const gchar *
+session_get_login1_session_id (Session *session)
+{
+ g_return_val_if_fail (session != NULL, NULL);
+ return session->priv->login1_session_id;
+}
+
const gchar *
session_get_console_kit_cookie (Session *session)
{
const gchar *session_get_username (Session *session);
+const gchar *session_get_login1_session_id (Session *session);
+
const gchar *session_get_console_kit_cookie (Session *session);
void session_respond (Session *session, struct pam_response *response);
test-upstart-login \
test-dbus \
test-lock-seat \
+ test-lock-seat-after-vt-switch \
test-lock-seat-resettable \
test-lock-seat-return-session \
test-lock-session \
--- /dev/null
+#
+# Check that a seat is locked properly when it has been unlocked by switching
+# back to the user session and using the screensaver to unlock it.
+#
+
+[SeatDefaults]
+autologin-user=have-password1
+user-session=default
+
+#?*START-DAEMON
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER-0 START VT=7 SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-0 INDICATE-READY
+#?XSERVER-0 INDICATE-READY
+#?XSERVER-0 ACCEPT-CONNECT
+
+# Session starts
+#?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1
+#?LOGIN1 ACTIVATE-SESSION SESSION=c0
+#?XSERVER-0 ACCEPT-CONNECT
+#?SESSION-X-0 CONNECT-XSERVER
+
+# Lock the seat
+#?*SESSION-X-0 LOCK-SEAT
+#?SESSION-X-0 LOCK-SEAT
+
+# New X server starts
+#?XSERVER-1 START VT=8 SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-1 INDICATE-READY
+#?XSERVER-1 INDICATE-READY
+#?XSERVER-1 ACCEPT-CONNECT
+
+# Session is locked
+#?LOGIN1 LOCK-SESSION SESSION=c0
+
+# Greeter starts
+#?GREETER-X-1 START XDG_SEAT=seat0 XDG_VTNR=8 XDG_SESSION_CLASS=greeter
+#?XSERVER-1 ACCEPT-CONNECT
+#?GREETER-X-1 CONNECT-XSERVER
+#?GREETER-X-1 CONNECT-TO-DAEMON
+#?GREETER-X-1 CONNECTED-TO-DAEMON
+#?GREETER-X-1 LOCK-HINT
+
+# Session is switched to greeter
+#?LOGIN1 ACTIVATE-SESSION SESSION=c1
+#?VT ACTIVATE VT=8
+
+# External program switches back to the first session
+#?*UPDATE-SEAT ID=seat0 ACTIVE-SESSION=c0
+
+# Session is unlocked using the screensaver
+#?*UNLOCK-SESSION SESSION=c0
+#?RUNNER UNLOCK-SESSION SESSION=c0
+
+# Lock the seat again
+#?*SESSION-X-0 LOCK-SEAT
+#?SESSION-X-0 LOCK-SEAT
+
+# New X server starts (this is a "bug")
+#?XSERVER-2 START VT=9 SEAT=seat0
+#?*XSERVER-2 INDICATE-READY
+#?XSERVER-2 INDICATE-READY
+#?XSERVER-2 ACCEPT-CONNECT
+
+# Session is locked
+#?LOGIN1 LOCK-SESSION SESSION=c0
+
+# Session is switched to greeter
+#?LOGIN1 ACTIVATE-SESSION SESSION=c1
+
+# The unnecessary X server is killed
+#?XSERVER-2 TERMINATE SIGNAL=15
+
+# Cleanup
+#?*STOP-DAEMON
+#?SESSION-X-0 TERMINATE SIGNAL=15
+#?XSERVER-0 TERMINATE SIGNAL=15
+#?GREETER-X-1 TERMINATE SIGNAL=15
+#?XSERVER-1 TERMINATE SIGNAL=15
+#?RUNNER DAEMON-EXIT STATUS=0
gchar *path;
gboolean can_graphical;
gboolean can_multi_session;
+ gchar *active_session;
} Login1Seat;
static GList *login1_seats = NULL;
static AccountsUser *get_accounts_user_by_uid (guint uid);
static AccountsUser *get_accounts_user_by_name (const gchar *username);
static void accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_signal);
+static Login1Session *find_login1_session (const gchar *id);
static gboolean
kill_timeout_cb (gpointer data)
seat->can_multi_session = strcmp (v, "TRUE") == 0;
g_variant_builder_add (&invalidated_properties, "s", "CanMultiSession");
}
+ v = g_hash_table_lookup (params, "ACTIVE-SESSION");
+ if (v)
+ {
+ g_free (seat->active_session);
+ seat->active_session = g_strdup (v);
+ g_variant_builder_add (&invalidated_properties, "s", "ActiveSession");
+ }
g_dbus_connection_emit_signal (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
NULL,
check_status (status_text);
g_free (status_text);
}
+ else if (strcmp (name, "UNLOCK-SESSION") == 0)
+ {
+ gchar *status_text, *id;
+ Login1Session *session;
+
+ id = g_hash_table_lookup (params, "SESSION");
+ session = find_login1_session (id);
+ if (session)
+ {
+ if (!session->locked)
+ g_warning ("Session %s is not locked", id);
+ session->locked = FALSE;
+ }
+ else
+ g_warning ("Unknown session %s", id);
+
+ status_text = g_strdup_printf ("RUNNER UNLOCK-SESSION SESSION=%s", id);
+ check_status (status_text);
+ g_free (status_text);
+ }
/* Forward to external processes */
else if (g_str_has_prefix (name, "SESSION-") ||
g_str_has_prefix (name, "GREETER-") ||
return g_variant_new_boolean (seat->can_multi_session);
else if (strcmp (property_name, "Id") == 0)
return g_variant_new_string (seat->id);
+ else if (strcmp (property_name, "ActiveSession") == 0)
+ {
+ if (seat->active_session)
+ {
+ gchar *path;
+ GVariant *ret;
+
+ path = g_strdup_printf ("/org/freedesktop/login1/session/%s", seat->active_session);
+ ret = g_variant_new ("(so)", seat->active_session, path);
+ g_free (path);
+
+ return ret;
+ }
+ else
+ return NULL;
+ }
else
return NULL;
}
" <interface name='org.freedesktop.login1.Seat'>"
" <property name='CanGraphical' type='b' access='read'/>"
" <property name='CanMultiSession' type='b' access='read'/>"
+ " <property name='ActiveSession' type='(so)' access='read'/>"
" <property name='Id' type='s' access='read'/>"
" </interface>"
"</node>";
seat->path = g_strdup_printf ("/org/freedesktop/login1/seat/%s", seat->id);
seat->can_graphical = TRUE;
seat->can_multi_session = TRUE;
+ seat->active_session = NULL;
login1_seat_info = g_dbus_node_info_new_for_xml (login1_seat_interface, &error);
if (error)
login1_seats = g_list_remove (login1_seats, seat);
g_free (seat->id);
g_free (seat->path);
+ g_free (seat->active_session);
g_free (seat);
}
--- /dev/null
+#!/bin/sh
+./src/dbus-env ./src/test-runner lock-seat-after-vt-switch test-gobject-greeter