summaryrefslogtreecommitdiff
path: root/mate-session
diff options
context:
space:
mode:
Diffstat (limited to 'mate-session')
-rw-r--r--mate-session/gsm-systemd.c65
-rw-r--r--mate-session/gsm-systemd.h2
2 files changed, 67 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)
{
diff --git a/mate-session/gsm-systemd.h b/mate-session/gsm-systemd.h
index 5d6b654..c00ec03 100644
--- a/mate-session/gsm-systemd.h
+++ b/mate-session/gsm-systemd.h
@@ -76,6 +76,8 @@ gboolean gsm_systemd_can_hibernate (GsmSystemd *manager);
gboolean gsm_systemd_can_suspend (GsmSystemd *manager);
+gboolean gsm_systemd_is_last_session_for_user (GsmSystemd *manager);
+
void gsm_systemd_attempt_stop (GsmSystemd *manager);
void gsm_systemd_attempt_restart (GsmSystemd *manager);