[gnome-session/wip/rstrode/kill-bus-clients: 3/4] system: add api for detecting if this is the last session for a user
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session/wip/rstrode/kill-bus-clients: 3/4] system: add api for detecting if this is the last session for a user
- Date: Tue, 20 Jun 2017 21:05:23 +0000 (UTC)
commit d905eea8dd7e29b663e79fc8c64ac0fe2f7063a7
Author: Ray Strode <rstrode redhat com>
Date: Tue Jun 20 16:51:00 2017 -0400
system: add api for detecting if this is the last session for a user
gnome-session/gsm-consolekit.c | 7 ++++
gnome-session/gsm-system.c | 7 ++++
gnome-session/gsm-system.h | 3 ++
gnome-session/gsm-systemd.c | 61 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/gnome-session/gsm-consolekit.c b/gnome-session/gsm-consolekit.c
index 4de5c1e..3d3891e 100644
--- a/gnome-session/gsm-consolekit.c
+++ b/gnome-session/gsm-consolekit.c
@@ -1039,6 +1039,12 @@ gsm_consolekit_complete_shutdown (GsmSystem *system)
gsm_consolekit_attempt_stop (system);
}
+static gboolean
+gsm_consolekit_is_last_session_for_user (GsmSystem *system)
+{
+ return FALSE;
+}
+
static void
gsm_consolekit_system_init (GsmSystemInterface *iface)
{
@@ -1057,6 +1063,7 @@ gsm_consolekit_system_init (GsmSystemInterface *iface)
iface->remove_inhibitor = gsm_consolekit_remove_inhibitor;
iface->prepare_shutdown = gsm_consolekit_prepare_shutdown;
iface->complete_shutdown = gsm_consolekit_complete_shutdown;
+ iface->is_last_session_for_user = gsm_consolekit_is_last_session_for_user;
}
GsmConsolekit *
diff --git a/gnome-session/gsm-system.c b/gnome-session/gsm-system.c
index c24a955..a78409d 100644
--- a/gnome-session/gsm-system.c
+++ b/gnome-session/gsm-system.c
@@ -97,6 +97,7 @@ gsm_system_null_init_iface (GsmSystemInterface *iface)
iface->remove_inhibitor = (void *) do_nothing;
iface->prepare_shutdown = (void *) do_nothing;
iface->complete_shutdown = (void *) do_nothing;
+ iface->is_last_session_for_user = (void *) return_false;
}
static void
@@ -218,6 +219,12 @@ gsm_system_is_login_session (GsmSystem *system)
return GSM_SYSTEM_GET_IFACE (system)->is_login_session (system);
}
+gboolean
+gsm_system_is_last_session_for_user (GsmSystem *system)
+{
+ return GSM_SYSTEM_GET_IFACE (system)->is_last_session_for_user (system);
+}
+
/**
* gsm_system_is_active:
*
diff --git a/gnome-session/gsm-system.h b/gnome-session/gsm-system.h
index cc1c06a..3a34b50 100644
--- a/gnome-session/gsm-system.h
+++ b/gnome-session/gsm-system.h
@@ -70,6 +70,7 @@ struct _GsmSystemInterface
void (* prepare_shutdown) (GsmSystem *system,
gboolean restart);
void (* complete_shutdown)(GsmSystem *system);
+ gboolean (* is_last_session_for_user) (GsmSystem *system);
};
enum _GsmSystemError {
@@ -106,6 +107,8 @@ void gsm_system_set_session_idle (GsmSystem *system,
gboolean gsm_system_is_login_session (GsmSystem *system);
+gboolean gsm_system_is_last_session_for_user (GsmSystem *system);
+
gboolean gsm_system_is_active (GsmSystem *system);
void gsm_system_add_inhibitor (GsmSystem *system,
diff --git a/gnome-session/gsm-systemd.c b/gnome-session/gsm-systemd.c
index ee43bfa..1a257bd 100644
--- a/gnome-session/gsm-systemd.c
+++ b/gnome-session/gsm-systemd.c
@@ -889,6 +889,66 @@ gsm_systemd_complete_shutdown (GsmSystem *system)
drop_delay_inhibitor (systemd);
}
+static gboolean
+gsm_systemd_is_last_session_for_user (GsmSystem *system)
+{
+ 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) {
+ 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;
+ }
+
+ is_last_session = FALSE;
+ }
+
+ for (i = 0; sessions[i]; i++)
+ free (sessions[i]);
+ free (sessions);
+
+ return is_last_session;
+}
+
static void
gsm_systemd_system_init (GsmSystemInterface *iface)
{
@@ -907,6 +967,7 @@ gsm_systemd_system_init (GsmSystemInterface *iface)
iface->remove_inhibitor = gsm_systemd_remove_inhibitor;
iface->prepare_shutdown = gsm_systemd_prepare_shutdown;
iface->complete_shutdown = gsm_systemd_complete_shutdown;
+ iface->is_last_session_for_user = gsm_systemd_is_last_session_for_user;
}
GsmSystemd *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]