summaryrefslogtreecommitdiffstats
path: root/core/modules/idleaction
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-27 17:31:40 +0100
committerSimon Rettberg2017-11-27 17:31:40 +0100
commit266160d76a4f984e0eb224e23396de99e6cde982 (patch)
treebc31e08651ed0e0b6e58407135d8524bb6ca2ffc /core/modules/idleaction
parentADD FILE (diff)
downloadmltk-266160d76a4f984e0eb224e23396de99e6cde982.tar.gz
mltk-266160d76a4f984e0eb224e23396de99e6cde982.tar.xz
mltk-266160d76a4f984e0eb224e23396de99e6cde982.zip
[idleaction] Fix active user counting
Diffstat (limited to 'core/modules/idleaction')
-rwxr-xr-xcore/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script21
1 files changed, 17 insertions, 4 deletions
diff --git a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script
index f3afc579..cfe042f4 100755
--- a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script
+++ b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script
@@ -9,6 +9,19 @@ CRONFILE="/etc/cron.d/idleaction-shutdown_schedule"
IDLEHINT="/run/openslx/idlehint"
NOW=$(date +%s)
+get_sessions() {
+ local LEGEND State Class
+ LEGEND=
+ loginctl --help 2>&1 | grep -q -- '--no-legend' && LEGEND="--no-legend"
+ for SESSION in $(loginctl $LEGEND | awk '{print $1}'); do
+ unset Display Remote State
+ eval $(loginctl -p State -p Class show-session "$SESSION")
+ if [ "$State" = "active" -o "$State" = "online" ] && [ "$Class" = "user" ]; then
+ echo "$SESSION"
+ fi
+ done
+}
+
#
# 1) Check for idle timeout
#
@@ -16,9 +29,9 @@ if [ -n "${SLX_LOGOUT_TIMEOUT}" ] && [ "${SLX_LOGOUT_TIMEOUT}" -gt 0 ]; then
# Logout timeout is set, see which users we should kick
IS_IDLE=yes
# get all sessions
- SESSIONS=$(loginctl | awk '{print $1}')
+ SESSIONS=$(get_sessions)
if [ -n "$SESSIONS" ]; then
- TMP="/dev/shm/idlecheck.tmp"
+ TMP="/run/openslx/idlecheck.tmp"
# Iterate over sessions
for ses in $SESSIONS; do
# Get information
@@ -79,8 +92,8 @@ if [ -n "${SLX_LOGOUT_TIMEOUT}" ] && [ "${SLX_LOGOUT_TIMEOUT}" -gt 0 ]; then
else
# No logout timeout is set, take shortcut for shutdown/suspend timeout (if set)
if [ -n "$SLX_SHUTDOWN_TIMEOUT" ] || [ -n "$SLX_SYSTEM_STANDBY_TIMEOUT" ]; then
- SESSIONS=$(loginctl | wc -l)
- if [ "$SESSIONS" = "0" ]; then
+ SESSIONS=$(get_sessions)
+ if [ -z "$SESSIONS" ]; then
[ ! -e "$IDLEHINT" ] && echo "$NOW" > "$IDLEHINT"
else
rm -f -- "$IDLEHINT"