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 /common | |
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.
Diffstat (limited to 'common')
-rw-r--r-- | common/gdm-common.c | 47 | ||||
-rw-r--r-- | common/gdm-common.h | 2 |
2 files changed, 36 insertions, 13 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, |