|
|
c90517 |
From f4e7c422bec2167c9648cb063f0cb204789d5f05 Mon Sep 17 00:00:00 2001
|
|
|
c90517 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
c90517 |
Date: Wed, 1 Aug 2018 16:34:30 -0400
|
|
|
c90517 |
Subject: [PATCH 07/48] common: dedupe gdm_get_login_window_session_id
|
|
|
c90517 |
|
|
|
c90517 |
Right now there are two slightly different cut-and-pastes of
|
|
|
c90517 |
the function to get the session id of the login session in
|
|
|
c90517 |
the code.
|
|
|
c90517 |
|
|
|
c90517 |
This commit deduplicates them.
|
|
|
c90517 |
---
|
|
|
c90517 |
common/gdm-common.c | 47 ++++++++++++++++++++++++++++++++------------
|
|
|
c90517 |
common/gdm-common.h | 2 ++
|
|
|
c90517 |
daemon/gdm-manager.c | 4 ++--
|
|
|
c90517 |
3 files changed, 38 insertions(+), 15 deletions(-)
|
|
|
c90517 |
|
|
|
c90517 |
diff --git a/common/gdm-common.c b/common/gdm-common.c
|
|
|
c90517 |
index c44fa998d..00daf0df8 100644
|
|
|
c90517 |
--- a/common/gdm-common.c
|
|
|
c90517 |
+++ b/common/gdm-common.c
|
|
|
c90517 |
@@ -364,186 +364,207 @@ create_transient_display (GDBusConnection *connection,
|
|
|
c90517 |
|
|
|
c90517 |
static gboolean
|
|
|
c90517 |
activate_session_id (GDBusConnection *connection,
|
|
|
c90517 |
const char *seat_id,
|
|
|
c90517 |
const char *session_id)
|
|
|
c90517 |
{
|
|
|
c90517 |
GError *local_error = NULL;
|
|
|
c90517 |
GVariant *reply;
|
|
|
c90517 |
|
|
|
c90517 |
reply = g_dbus_connection_call_sync (connection,
|
|
|
c90517 |
"org.freedesktop.login1",
|
|
|
c90517 |
"/org/freedesktop/login1",
|
|
|
c90517 |
"org.freedesktop.login1.Manager",
|
|
|
c90517 |
"ActivateSessionOnSeat",
|
|
|
c90517 |
g_variant_new ("(ss)", session_id, seat_id),
|
|
|
c90517 |
NULL,
|
|
|
c90517 |
G_DBUS_CALL_FLAGS_NONE,
|
|
|
c90517 |
-1,
|
|
|
c90517 |
NULL, &local_error);
|
|
|
c90517 |
if (reply == NULL) {
|
|
|
c90517 |
g_warning ("Unable to activate session: %s", local_error->message);
|
|
|
c90517 |
g_error_free (local_error);
|
|
|
c90517 |
return FALSE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
g_variant_unref (reply);
|
|
|
c90517 |
|
|
|
c90517 |
return TRUE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
-static gboolean
|
|
|
c90517 |
-get_login_window_session_id (const char *seat_id,
|
|
|
c90517 |
- char **session_id)
|
|
|
c90517 |
+gboolean
|
|
|
c90517 |
+gdm_get_login_window_session_id (const char *seat_id,
|
|
|
c90517 |
+ char **session_id)
|
|
|
c90517 |
{
|
|
|
c90517 |
gboolean ret;
|
|
|
c90517 |
int res, i;
|
|
|
c90517 |
char **sessions;
|
|
|
c90517 |
+ char *service_id;
|
|
|
c90517 |
char *service_class;
|
|
|
c90517 |
char *state;
|
|
|
c90517 |
|
|
|
c90517 |
res = sd_seat_get_sessions (seat_id, &sessions, NULL, NULL);
|
|
|
c90517 |
if (res < 0) {
|
|
|
c90517 |
g_debug ("Failed to determine sessions: %s", strerror (-res));
|
|
|
c90517 |
return FALSE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
if (sessions == NULL || sessions[0] == NULL) {
|
|
|
c90517 |
*session_id = NULL;
|
|
|
c90517 |
- ret = TRUE;
|
|
|
c90517 |
+ ret = FALSE;
|
|
|
c90517 |
goto out;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
for (i = 0; sessions[i]; i ++) {
|
|
|
c90517 |
+
|
|
|
c90517 |
res = sd_session_get_class (sessions[i], &service_class);
|
|
|
c90517 |
if (res < 0) {
|
|
|
c90517 |
+ if (res == -ENOENT) {
|
|
|
c90517 |
+ free (service_class);
|
|
|
c90517 |
+ continue;
|
|
|
c90517 |
+ }
|
|
|
c90517 |
+
|
|
|
c90517 |
g_debug ("failed to determine class of session %s: %s", sessions[i], strerror (-res));
|
|
|
c90517 |
ret = FALSE;
|
|
|
c90517 |
goto out;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
if (strcmp (service_class, "greeter") != 0) {
|
|
|
c90517 |
free (service_class);
|
|
|
c90517 |
continue;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
free (service_class);
|
|
|
c90517 |
|
|
|
c90517 |
ret = sd_session_get_state (sessions[i], &state);
|
|
|
c90517 |
if (ret < 0) {
|
|
|
c90517 |
g_debug ("failed to determine state of session %s: %s", sessions[i], strerror (-res));
|
|
|
c90517 |
ret = FALSE;
|
|
|
c90517 |
goto out;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
if (g_strcmp0 (state, "closing") == 0) {
|
|
|
c90517 |
free (state);
|
|
|
c90517 |
continue;
|
|
|
c90517 |
}
|
|
|
c90517 |
free (state);
|
|
|
c90517 |
|
|
|
c90517 |
- *session_id = g_strdup (sessions[i]);
|
|
|
c90517 |
- ret = TRUE;
|
|
|
c90517 |
- break;
|
|
|
c90517 |
+ res = sd_session_get_service (sessions[i], &service_id);
|
|
|
c90517 |
+ if (res < 0) {
|
|
|
c90517 |
+ g_debug ("failed to determine service of session %s: %s", sessions[i], strerror (-res));
|
|
|
c90517 |
+ ret = FALSE;
|
|
|
c90517 |
+ goto out;
|
|
|
c90517 |
+ }
|
|
|
c90517 |
|
|
|
c90517 |
+ if (strcmp (service_id, "gdm-launch-environment") == 0) {
|
|
|
c90517 |
+ *session_id = g_strdup (sessions[i]);
|
|
|
c90517 |
+ ret = TRUE;
|
|
|
c90517 |
+
|
|
|
c90517 |
+ free (service_id);
|
|
|
c90517 |
+ goto out;
|
|
|
c90517 |
+ }
|
|
|
c90517 |
+
|
|
|
c90517 |
+ free (service_id);
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
*session_id = NULL;
|
|
|
c90517 |
- ret = TRUE;
|
|
|
c90517 |
+ ret = FALSE;
|
|
|
c90517 |
|
|
|
c90517 |
out:
|
|
|
c90517 |
- for (i = 0; sessions[i]; i ++) {
|
|
|
c90517 |
- free (sessions[i]);
|
|
|
c90517 |
- }
|
|
|
c90517 |
+ if (sessions) {
|
|
|
c90517 |
+ for (i = 0; sessions[i]; i ++) {
|
|
|
c90517 |
+ free (sessions[i]);
|
|
|
c90517 |
+ }
|
|
|
c90517 |
|
|
|
c90517 |
- free (sessions);
|
|
|
c90517 |
+ free (sessions);
|
|
|
c90517 |
+ }
|
|
|
c90517 |
|
|
|
c90517 |
return ret;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
static gboolean
|
|
|
c90517 |
goto_login_session (GDBusConnection *connection,
|
|
|
c90517 |
GError **error)
|
|
|
c90517 |
{
|
|
|
c90517 |
gboolean ret;
|
|
|
c90517 |
int res;
|
|
|
c90517 |
char *our_session;
|
|
|
c90517 |
char *session_id;
|
|
|
c90517 |
char *seat_id;
|
|
|
c90517 |
|
|
|
c90517 |
ret = FALSE;
|
|
|
c90517 |
session_id = NULL;
|
|
|
c90517 |
seat_id = NULL;
|
|
|
c90517 |
|
|
|
c90517 |
/* First look for any existing LoginWindow sessions on the seat.
|
|
|
c90517 |
If none are found, create a new one. */
|
|
|
c90517 |
|
|
|
c90517 |
/* Note that we mostly use free () here, instead of g_free ()
|
|
|
c90517 |
* since the data allocated is from libsystemd-logind, which
|
|
|
c90517 |
* does not use GLib's g_malloc (). */
|
|
|
c90517 |
|
|
|
c90517 |
res = sd_pid_get_session (0, &our_session);
|
|
|
c90517 |
if (res < 0) {
|
|
|
c90517 |
g_debug ("failed to determine own session: %s", strerror (-res));
|
|
|
c90517 |
g_set_error (error, GDM_COMMON_ERROR, 0, _("Could not identify the current session."));
|
|
|
c90517 |
|
|
|
c90517 |
return FALSE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
res = sd_session_get_seat (our_session, &seat_id);
|
|
|
c90517 |
free (our_session);
|
|
|
c90517 |
if (res < 0) {
|
|
|
c90517 |
g_debug ("failed to determine own seat: %s", strerror (-res));
|
|
|
c90517 |
g_set_error (error, GDM_COMMON_ERROR, 0, _("Could not identify the current seat."));
|
|
|
c90517 |
|
|
|
c90517 |
return FALSE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
res = sd_seat_can_multi_session (seat_id);
|
|
|
c90517 |
if (res < 0) {
|
|
|
c90517 |
free (seat_id);
|
|
|
c90517 |
|
|
|
c90517 |
g_debug ("failed to determine whether seat can do multi session: %s", strerror (-res));
|
|
|
c90517 |
g_set_error (error, GDM_COMMON_ERROR, 0, _("The system is unable to determine whether to switch to an existing login screen or start up a new login screen."));
|
|
|
c90517 |
|
|
|
c90517 |
return FALSE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
if (res == 0) {
|
|
|
c90517 |
free (seat_id);
|
|
|
c90517 |
|
|
|
c90517 |
g_set_error (error, GDM_COMMON_ERROR, 0, _("The system is unable to start up a new login screen."));
|
|
|
c90517 |
|
|
|
c90517 |
return FALSE;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
- res = get_login_window_session_id (seat_id, &session_id);
|
|
|
c90517 |
+ res = gdm_get_login_window_session_id (seat_id, &session_id);
|
|
|
c90517 |
if (res && session_id != NULL) {
|
|
|
c90517 |
res = activate_session_id (connection, seat_id, session_id);
|
|
|
c90517 |
|
|
|
c90517 |
if (res) {
|
|
|
c90517 |
ret = TRUE;
|
|
|
c90517 |
}
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
if (! ret && g_strcmp0 (seat_id, "seat0") == 0) {
|
|
|
c90517 |
res = create_transient_display (connection, error);
|
|
|
c90517 |
if (res) {
|
|
|
c90517 |
ret = TRUE;
|
|
|
c90517 |
}
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
free (seat_id);
|
|
|
c90517 |
g_free (session_id);
|
|
|
c90517 |
|
|
|
c90517 |
return ret;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
gboolean
|
|
|
c90517 |
gdm_goto_login_session (GError **error)
|
|
|
c90517 |
{
|
|
|
c90517 |
GError *local_error;
|
|
|
c90517 |
GDBusConnection *connection;
|
|
|
c90517 |
|
|
|
c90517 |
local_error = NULL;
|
|
|
c90517 |
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &local_error);
|
|
|
c90517 |
if (connection == NULL) {
|
|
|
c90517 |
diff --git a/common/gdm-common.h b/common/gdm-common.h
|
|
|
c90517 |
index 8d83a1246..c9cbd9c48 100644
|
|
|
c90517 |
--- a/common/gdm-common.h
|
|
|
c90517 |
+++ b/common/gdm-common.h
|
|
|
c90517 |
@@ -26,51 +26,53 @@
|
|
|
c90517 |
#include <errno.h>
|
|
|
c90517 |
|
|
|
c90517 |
#define VE_IGNORE_EINTR(expr) \
|
|
|
c90517 |
do { \
|
|
|
c90517 |
errno = 0; \
|
|
|
c90517 |
expr; \
|
|
|
c90517 |
} while G_UNLIKELY (errno == EINTR);
|
|
|
c90517 |
|
|
|
c90517 |
GQuark gdm_common_error_quark (void);
|
|
|
c90517 |
#define GDM_COMMON_ERROR gdm_common_error_quark()
|
|
|
c90517 |
|
|
|
c90517 |
typedef char * (*GdmExpandVarFunc) (const char *var,
|
|
|
c90517 |
gpointer user_data);
|
|
|
c90517 |
|
|
|
c90517 |
G_BEGIN_DECLS
|
|
|
c90517 |
|
|
|
c90517 |
int gdm_wait_on_pid (int pid);
|
|
|
c90517 |
int gdm_wait_on_and_disown_pid (int pid,
|
|
|
c90517 |
int timeout);
|
|
|
c90517 |
int gdm_signal_pid (int pid,
|
|
|
c90517 |
int signal);
|
|
|
c90517 |
gboolean gdm_get_pwent_for_name (const char *name,
|
|
|
c90517 |
struct passwd **pwentp);
|
|
|
c90517 |
|
|
|
c90517 |
gboolean gdm_clear_close_on_exec_flag (int fd);
|
|
|
c90517 |
|
|
|
c90517 |
const char * gdm_make_temp_dir (char *template);
|
|
|
c90517 |
|
|
|
c90517 |
char *gdm_generate_random_bytes (gsize size,
|
|
|
c90517 |
GError **error);
|
|
|
c90517 |
+gboolean gdm_get_login_window_session_id (const char *seat_id,
|
|
|
c90517 |
+ char **session_id);
|
|
|
c90517 |
gboolean gdm_goto_login_session (GError **error);
|
|
|
c90517 |
|
|
|
c90517 |
GPtrArray *gdm_get_script_environment (const char *username,
|
|
|
c90517 |
const char *display_name,
|
|
|
c90517 |
const char *display_hostname,
|
|
|
c90517 |
const char *display_x11_authority_file);
|
|
|
c90517 |
gboolean gdm_run_script (const char *dir,
|
|
|
c90517 |
const char *username,
|
|
|
c90517 |
const char *display_name,
|
|
|
c90517 |
const char *display_hostname,
|
|
|
c90517 |
const char *display_x11_authority_file);
|
|
|
c90517 |
|
|
|
c90517 |
gboolean gdm_shell_var_is_valid_char (char c,
|
|
|
c90517 |
gboolean first);
|
|
|
c90517 |
char * gdm_shell_expand (const char *str,
|
|
|
c90517 |
GdmExpandVarFunc expand_func,
|
|
|
c90517 |
gpointer user_data);
|
|
|
c90517 |
|
|
|
c90517 |
G_END_DECLS
|
|
|
c90517 |
|
|
|
c90517 |
#endif /* _GDM_COMMON_H */
|
|
|
c90517 |
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
|
|
|
c90517 |
index 7a5554e9d..375ef6f80 100644
|
|
|
c90517 |
--- a/daemon/gdm-manager.c
|
|
|
c90517 |
+++ b/daemon/gdm-manager.c
|
|
|
c90517 |
@@ -1444,61 +1444,61 @@ get_login_window_session_id (const char *seat_id,
|
|
|
c90517 |
ret = TRUE;
|
|
|
c90517 |
|
|
|
c90517 |
free (service_id);
|
|
|
c90517 |
goto out;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
free (service_id);
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
*session_id = NULL;
|
|
|
c90517 |
ret = FALSE;
|
|
|
c90517 |
|
|
|
c90517 |
out:
|
|
|
c90517 |
if (sessions) {
|
|
|
c90517 |
for (i = 0; sessions[i]; i ++) {
|
|
|
c90517 |
free (sessions[i]);
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
free (sessions);
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
return ret;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
static void
|
|
|
c90517 |
activate_login_window_session_on_seat (GdmManager *self,
|
|
|
c90517 |
const char *seat_id)
|
|
|
c90517 |
{
|
|
|
c90517 |
char *session_id;
|
|
|
c90517 |
|
|
|
c90517 |
- if (!get_login_window_session_id (seat_id, &session_id)) {
|
|
|
c90517 |
+ if (!gdm_get_login_window_session_id (seat_id, &session_id)) {
|
|
|
c90517 |
return;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
if (session_id) {
|
|
|
c90517 |
activate_session_id (self, seat_id, session_id);
|
|
|
c90517 |
g_free (session_id);
|
|
|
c90517 |
}
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
static void
|
|
|
c90517 |
maybe_activate_other_session (GdmManager *self,
|
|
|
c90517 |
GdmDisplay *old_display)
|
|
|
c90517 |
{
|
|
|
c90517 |
char *seat_id = NULL;
|
|
|
c90517 |
char *session_id;
|
|
|
c90517 |
int ret;
|
|
|
c90517 |
|
|
|
c90517 |
g_object_get (G_OBJECT (old_display),
|
|
|
c90517 |
"seat-id", &seat_id,
|
|
|
c90517 |
NULL);
|
|
|
c90517 |
|
|
|
c90517 |
ret = sd_seat_get_active (seat_id, &session_id, NULL);
|
|
|
c90517 |
|
|
|
c90517 |
if (ret == 0) {
|
|
|
c90517 |
GdmDisplay *display;
|
|
|
c90517 |
|
|
|
c90517 |
display = gdm_display_store_find (self->priv->display_store,
|
|
|
c90517 |
lookup_by_session_id,
|
|
|
c90517 |
(gpointer) session_id);
|
|
|
c90517 |
|
|
|
c90517 |
@@ -2082,61 +2082,61 @@ on_user_session_exited (GdmSession *session,
|
|
|
c90517 |
|
|
|
c90517 |
static void
|
|
|
c90517 |
on_user_session_died (GdmSession *session,
|
|
|
c90517 |
int signal_number,
|
|
|
c90517 |
GdmManager *manager)
|
|
|
c90517 |
{
|
|
|
c90517 |
g_debug ("GdmManager: session died with signal %s", strsignal (signal_number));
|
|
|
c90517 |
remove_user_session (manager, session);
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
static char *
|
|
|
c90517 |
get_display_device (GdmManager *manager,
|
|
|
c90517 |
GdmDisplay *display)
|
|
|
c90517 |
{
|
|
|
c90517 |
/* systemd finds the display device out on its own based on the display */
|
|
|
c90517 |
return NULL;
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
static void
|
|
|
c90517 |
on_session_reauthenticated (GdmSession *session,
|
|
|
c90517 |
const char *service_name,
|
|
|
c90517 |
GdmManager *manager)
|
|
|
c90517 |
{
|
|
|
c90517 |
gboolean fail_if_already_switched = FALSE;
|
|
|
c90517 |
|
|
|
c90517 |
if (gdm_session_get_display_mode (session) == GDM_SESSION_DISPLAY_MODE_REUSE_VT) {
|
|
|
c90517 |
const char *seat_id;
|
|
|
c90517 |
char *session_id;
|
|
|
c90517 |
|
|
|
c90517 |
seat_id = gdm_session_get_display_seat_id (session);
|
|
|
c90517 |
- if (get_login_window_session_id (seat_id, &session_id)) {
|
|
|
c90517 |
+ if (gdm_get_login_window_session_id (seat_id, &session_id)) {
|
|
|
c90517 |
GdmDisplay *display = gdm_display_store_find (manager->priv->display_store,
|
|
|
c90517 |
lookup_by_session_id,
|
|
|
c90517 |
(gpointer) session_id);
|
|
|
c90517 |
|
|
|
c90517 |
if (display != NULL) {
|
|
|
c90517 |
gdm_display_stop_greeter_session (display);
|
|
|
c90517 |
gdm_display_unmanage (display);
|
|
|
c90517 |
gdm_display_finish (display);
|
|
|
c90517 |
}
|
|
|
c90517 |
g_free (session_id);
|
|
|
c90517 |
}
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
/* There should already be a session running, so jump to its
|
|
|
c90517 |
* VT. In the event we're already on the right VT, (i.e. user
|
|
|
c90517 |
* used an unlock screen instead of a user switched login screen),
|
|
|
c90517 |
* then silently succeed and unlock the session.
|
|
|
c90517 |
*/
|
|
|
c90517 |
switch_to_compatible_user_session (manager, session, fail_if_already_switched);
|
|
|
c90517 |
}
|
|
|
c90517 |
|
|
|
c90517 |
static void
|
|
|
c90517 |
on_session_client_ready_for_session_to_start (GdmSession *session,
|
|
|
c90517 |
const char *service_name,
|
|
|
c90517 |
gboolean client_is_ready,
|
|
|
c90517 |
GdmManager *manager)
|
|
|
c90517 |
{
|
|
|
c90517 |
gboolean waiting_to_start_user_session;
|
|
|
c90517 |
|
|
|
c90517 |
if (client_is_ready) {
|
|
|
c90517 |
--
|
|
|
c90517 |
2.26.0
|
|
|
c90517 |
|