Commit 0e9f09da authored by Ray Strode's avatar Ray Strode Committed by Ray Strode

common: dedupe gdm_get_login_window_session_id

Right now there are two slightly different cut-and-pastes of
the function to get the session id of the login session in
the code.

This commit deduplicates them.
parent 23521432
......@@ -381,13 +381,14 @@ activate_session_id (GDBusConnection *connection,
return TRUE;
}
static gboolean
get_login_window_session_id (const char *seat_id,
char **session_id)
gboolean
gdm_get_login_window_session_id (const char *seat_id,
char **session_id)
{
gboolean ret;
int res, i;
char **sessions;
char *service_id;
char *service_class;
char *state;
......@@ -399,13 +400,19 @@ get_login_window_session_id (const char *seat_id,
if (sessions == NULL || sessions[0] == NULL) {
*session_id = NULL;
ret = TRUE;
ret = FALSE;
goto out;
}
for (i = 0; sessions[i]; i ++) {
res = sd_session_get_class (sessions[i], &service_class);
if (res < 0) {
if (res == -ENOENT) {
free (service_class);
continue;
}
g_debug ("failed to determine class of session %s: %s", sessions[i], strerror (-res));
ret = FALSE;
goto out;
......@@ -431,21 +438,35 @@ get_login_window_session_id (const char *seat_id,
}
free (state);
*session_id = g_strdup (sessions[i]);
ret = TRUE;
break;
res = sd_session_get_service (sessions[i], &service_id);
if (res < 0) {
g_debug ("failed to determine service of session %s: %s", sessions[i], strerror (-res));
ret = FALSE;
goto out;
}
if (strcmp (service_id, "gdm-launch-environment") == 0) {
*session_id = g_strdup (sessions[i]);
ret = TRUE;
free (service_id);
goto out;
}
free (service_id);
}
*session_id = NULL;
ret = TRUE;
ret = FALSE;
out:
for (i = 0; sessions[i]; i ++) {
free (sessions[i]);
}
if (sessions) {
for (i = 0; sessions[i]; i ++) {
free (sessions[i]);
}
free (sessions);
free (sessions);
}
return ret;
}
......@@ -506,7 +527,7 @@ goto_login_session (GDBusConnection *connection,
return FALSE;
}
res = get_login_window_session_id (seat_id, &session_id);
res = gdm_get_login_window_session_id (seat_id, &session_id);
if (res && session_id != NULL) {
res = activate_session_id (connection, seat_id, session_id);
......
......@@ -51,6 +51,8 @@ gboolean gdm_clear_close_on_exec_flag (int fd);
char *gdm_generate_random_bytes (gsize size,
GError **error);
gboolean gdm_get_login_window_session_id (const char *seat_id,
char **session_id);
gboolean gdm_goto_login_session (GError **error);
GPtrArray *gdm_get_script_environment (const char *username,
......
......@@ -1318,108 +1318,13 @@ maybe_start_pending_initial_login (GdmManager *manager,
g_free (user_session_seat_id);
}
static gboolean
get_login_window_session_id (const char *seat_id,
char **session_id)
{
gboolean ret;
int res, i;
char **sessions;
char *service_id;
char *service_class;
char *state;
res = sd_seat_get_sessions (seat_id, &sessions, NULL, NULL);
if (res < 0) {
g_debug ("Failed to determine sessions: %s", strerror (-res));
return FALSE;
}
if (sessions == NULL || sessions[0] == NULL) {
*session_id = NULL;
ret = FALSE;
goto out;
}
for (i = 0; sessions[i]; i ++) {
res = sd_session_get_class (sessions[i], &service_class);
if (res < 0) {
if (res == -ENOENT) {
free (service_class);
continue;
}
g_debug ("failed to determine class of session %s: %s", sessions[i], strerror (-res));
ret = FALSE;
goto out;
}
if (strcmp (service_class, "greeter") != 0) {
free (service_class);
continue;
}
free (service_class);
ret = sd_session_get_state (sessions[i], &state);
if (ret < 0) {
if (res == -ENOENT)
continue;
g_debug ("failed to determine state of session %s: %s", sessions[i], strerror (-res));
ret = FALSE;
goto out;
}
if (g_strcmp0 (state, "closing") == 0) {
free (state);
continue;
}
free (state);
res = sd_session_get_service (sessions[i], &service_id);
if (res < 0) {
if (res == -ENOENT)
continue;
g_debug ("failed to determine service of session %s: %s", sessions[i], strerror (-res));
ret = FALSE;
goto out;
}
if (strcmp (service_id, "gdm-launch-environment") == 0) {
*session_id = g_strdup (sessions[i]);
ret = TRUE;
free (service_id);
goto out;
}
free (service_id);
}
*session_id = NULL;
ret = FALSE;
out:
if (sessions) {
for (i = 0; sessions[i]; i ++) {
free (sessions[i]);
}
free (sessions);
}
return ret;
}
static void
activate_login_window_session_on_seat (GdmManager *self,
const char *seat_id)
{
char *session_id;
if (!get_login_window_session_id (seat_id, &session_id)) {
if (!gdm_get_login_window_session_id (seat_id, &session_id)) {
return;
}
......@@ -2059,7 +1964,7 @@ on_session_reauthenticated (GdmSession *session,
char *session_id;
seat_id = gdm_session_get_display_seat_id (session);
if (get_login_window_session_id (seat_id, &session_id)) {
if (gdm_get_login_window_session_id (seat_id, &session_id)) {
GdmDisplay *display = gdm_display_store_find (manager->priv->display_store,
lookup_by_session_id,
(gpointer) session_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment