diff options
author | Ray Strode <rstrode@redhat.com> | 2018-08-01 16:34:30 -0400 |
---|---|---|
committer | Ray Strode <halfline@gmail.com> | 2018-08-02 20:06:36 +0000 |
commit | 0e9f09da4897bdc4069298c8a4d189cd7f217f81 (patch) | |
tree | 719634e2d089d95bc0e3f1206b408fe3b753141e | |
parent | 235214328f23422a87da12b1d952bcbc2c174fcc (diff) | |
download | gdm-0e9f09da4897bdc4069298c8a4d189cd7f217f81.tar.gz |
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.
-rw-r--r-- | common/gdm-common.c | 47 | ||||
-rw-r--r-- | common/gdm-common.h | 2 | ||||
-rw-r--r-- | daemon/gdm-manager.c | 99 |
3 files changed, 38 insertions, 110 deletions
diff --git a/common/gdm-common.c b/common/gdm-common.c index a5b59242..613511c4 100644 --- a/common/gdm-common.c +++ b/common/gdm-common.c @@ -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); diff --git a/common/gdm-common.h b/common/gdm-common.h index e13c3a3d..bd8ac705 100644 --- a/common/gdm-common.h +++ b/common/gdm-common.h @@ -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, diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c index 2ec8d652..ac30aee9 100644 --- a/daemon/gdm-manager.c +++ b/daemon/gdm-manager.c @@ -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); |