diff options
author | Simon Rettberg | 2017-11-27 19:07:33 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-27 19:07:33 +0100 |
commit | 3ef4eafe45b49261865c82f2b7b7648c00d356b8 (patch) | |
tree | deb197991ed5c784b9bccca6b775cd5712112df0 /core/modules | |
parent | [idleaction] Fix active user counting (diff) | |
download | mltk-3ef4eafe45b49261865c82f2b7b7648c00d356b8.tar.gz mltk-3ef4eafe45b49261865c82f2b7b7648c00d356b8.tar.xz mltk-3ef4eafe45b49261865c82f2b7b7648c00d356b8.zip |
[idleaction] Fix shutdown after wakeup when cron tries to catch up
Diffstat (limited to 'core/modules')
3 files changed, 36 insertions, 8 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 cfe042f4..e9752eb4 100755 --- a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script +++ b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script @@ -144,7 +144,7 @@ write_crontab () [ -z "$HOUR" -o -z "$MINUTE" ] && invalid_time && continue [ "$HOUR" -lt 0 -o "$HOUR" -gt 23 ] && invalid_time && continue [ "$MINUTE" -lt 0 -o "$MINUTE" -gt 59 ] && invalid_time && continue - echo "$MINUTE $HOUR * * * root /opt/openslx/scripts/idleaction-scheduled_action $ACTION" >> "$CRONFILE" + echo "$MINUTE $HOUR * * * root /opt/openslx/scripts/idleaction-scheduled_action $ACTION --time $time" >> "$CRONFILE" done } diff --git a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action index 5c5f2a06..5e279c34 100755 --- a/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action +++ b/core/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action @@ -1,7 +1,7 @@ #!/bin/ash -if [ "$(whoami)" != "root" ]; then - echo "Only root can call this" +if ! touch "/run"; then + echo "Only root can call this" >&2 exit 1 fi @@ -12,15 +12,43 @@ if [ "$1" = "--detach" ]; then fi if [ $# -lt 1 ]; then - echo "$0 [--detach] <reboot|poweroff> [delay_minutes]" + echo "$0 [--detach] <reboot|poweroff> [delay_minutes]" >&2 exit 2 fi +DELAY= +TS= MODE=$1 -DELAY=$2 +shift + +while [ $# -gt 0 ]; do + if [ "$1" == "--time" ]; then + TS=$2 + shift + elif [ "$1" == "--delay" ]; then + DELAY=$2 + shift + else + break + fi + shift +done +[ -n "$1" ] && DELAY=$1 + +if [ -n "$TS" ]; then + # Sanity check for trigger by cron + NOW=$(date +%s) + SHOULD=$(date -d "today $TS" +%s) + DIFF=$(( NOW - SHOULD )) + DIFF=${DIFF#-} # DIFF = Abs($DIFF) + if [ "$DIFF" -gt 90 ]; then + echo "Timestamp mismatch, ignoring request." >&2 + exit 4 + fi +fi if [ "$MODE" != "reboot" ] && [ "$MODE" != "poweroff" ]; then - slxlog "idleaction-failed-call" "Invalid call to idleaction-scheduled_action. Mode '$MODE' unknown." + slxlog --echo "idleaction-failed-call" "Invalid call to idleaction-scheduled_action. Mode '$MODE' unknown." >&2 exit 3 fi diff --git a/core/modules/idleaction/data/opt/openslx/scripts/systemd-idleaction_init b/core/modules/idleaction/data/opt/openslx/scripts/systemd-idleaction_init index ae8af404..304b4a63 100755 --- a/core/modules/idleaction/data/opt/openslx/scripts/systemd-idleaction_init +++ b/core/modules/idleaction/data/opt/openslx/scripts/systemd-idleaction_init @@ -60,8 +60,8 @@ if [ -n "$TEST" ]; then fi if [ -n "$NEXT" ]; then - # Always assume RTC is UTC so rtcwake will not assume the RTC does DST changes - rtcwake -u -m no -t "$NEXT" + # Set -l and hope it does the right thing on DST + rtcwake -l -m no -t "$NEXT" else rtcwake -m disable fi |