diff options
author | Victor Kareh <[email protected]> | 2019-01-29 15:19:14 -0500 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2019-02-04 07:52:05 -0500 |
commit | 37d538eba3a6b36a6d739de4b7567a97203ada3a (patch) | |
tree | a55f46441b3e3394a9378f9d7b02ac3075b31813 /mate-session/gsm-systemd.c | |
parent | 409d9fcc735f6dfd6ada9d90360e045130379259 (diff) | |
download | mate-session-manager-37d538eba3a6b36a6d739de4b7567a97203ada3a.tar.bz2 mate-session-manager-37d538eba3a6b36a6d739de4b7567a97203ada3a.tar.xz |
systemd: add api for detecting if this is the last session for a user
https://bugzilla.gnome.org/show_bug.cgi?id=764029
Adapted from https://gitlab.gnome.org/GNOME/gnome-session/commit/f708bbbf
Diffstat (limited to 'mate-session/gsm-systemd.c')
-rw-r--r-- | mate-session/gsm-systemd.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/mate-session/gsm-systemd.c b/mate-session/gsm-systemd.c index 5eafaed..da3f23b 100644 --- a/mate-session/gsm-systemd.c +++ b/mate-session/gsm-systemd.c @@ -421,6 +421,71 @@ emit_stop_complete (GsmSystemd *manager, } } +gboolean +gsm_systemd_is_last_session_for_user (GsmSystemd *manager) +{ + char **sessions = NULL; + char *session = NULL; + gboolean is_last_session; + int ret, i; + + ret = sd_pid_get_session (getpid (), &session); + + if (ret != 0) { + return FALSE; + } + + ret = sd_uid_get_sessions (getuid (), FALSE, &sessions); + + if (ret <= 0) { + free (session); + return FALSE; + } + + is_last_session = TRUE; + for (i = 0; sessions[i]; i++) { + char *state = NULL; + char *type = NULL; + + if (g_strcmp0 (sessions[i], session) == 0) + continue; + + ret = sd_session_get_state (sessions[i], &state); + + if (ret != 0) + continue; + + if (g_strcmp0 (state, "closing") == 0) { + free (state); + continue; + } + free (state); + + ret = sd_session_get_type (sessions[i], &type); + + if (ret != 0) + continue; + + if (g_strcmp0 (type, "x11") != 0 && + g_strcmp0 (type, "wayland") != 0) { + free (type); + continue; + } + free (type); + + is_last_session = FALSE; + + break; + } + + for (i = 0; sessions[i]; i++) + free (sessions[i]); + free (sessions); + free (session); + + return is_last_session; +} + void gsm_systemd_attempt_restart (GsmSystemd *manager) { |