mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 12:03:11 +02:00
fix: shutdown timer crashing on every fire due to heredoc escaping bug
The hibernate-on-alarm-night case block in create_shutdown_check_script()
escaped $ as \$ for an unquoted heredoc, but the heredoc is opened with the
quoted delimiter <<'EOF', so the backslashes were written literally into
the deployed check script. Every timer fire since commit 0d54c5d hit a bash
syntax error and exited before evaluating the shutdown window, so the PC
never auto-shut-down (confirmed failing at 23:00/23:01 last night and 07:01
this morning). Also fixed an off-by-one (seq ... 24 -> 23) that was emitting
invalid OnCalendar=24:00:00 entries systemd had to ignore.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGHLfbAPmak6HtGJby57eo
This commit is contained in:
parent
66272dc95a
commit
12fe41049f
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"intent": "Fix the day-specific midnight shutdown timer silently failing on every fire (confirmed at 23:00/23:01 on 2026-06-21 and 07:01 on 2026-06-22), which caused the PC to stay on overnight and require a manual shutdown.",
|
||||||
|
"scope": [
|
||||||
|
"linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh",
|
||||||
|
"Deployed artifacts regenerated by this script: /usr/local/bin/day-specific-shutdown-check.sh, /etc/systemd/system/day-specific-shutdown.timer",
|
||||||
|
"Non-goal: did not change the shutdown schedule (kept at original 21:00 Mon-Wed / 22:00 Thu-Sun / 05:00 morning end) or the schedule-lenience protection check"
|
||||||
|
],
|
||||||
|
"changes": [
|
||||||
|
"create_shutdown_check_script(): removed spurious backslash-escaping of $ in the hibernate/poweroff case block (tomorrow_dow, wake_epoch). The heredoc uses the quoted delimiter <<'EOF', so $ was never expanded at generation time; the escaped \\$ was written literally into the deployed script, producing a bash syntax error ('syntax error near unexpected token (') on every single invocation since commit 0d54c5d introduced the hibernate-on-alarm-night feature.",
|
||||||
|
"create_shutdown_timer(): fixed off-by-one in `seq \"$earliest_hour\" 24` -> `23`, which was emitting invalid OnCalendar=*-*-* 24:00:00/24:30:00 entries that systemd logged as parse failures on every daemon-reload."
|
||||||
|
],
|
||||||
|
"verification": [
|
||||||
|
{
|
||||||
|
"command": "bash -n linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "No syntax errors in the setup script itself."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "sudo ./setup_midnight_shutdown.sh enable (redeployed) && bash -n /usr/local/bin/day-specific-shutdown-check.sh",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "Deployed check script now parses cleanly; previously failed with 'line 92: syntax error near unexpected token `(`'."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "sudo /usr/local/bin/day-specific-shutdown-check.sh",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "Logged: '2026-06-22 07:08:33: Skipping shutdown - not within shutdown window for Monday (current: 07:08)' — correct decision, no crash."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "sudo systemctl start day-specific-shutdown.service && systemctl status day-specific-shutdown.service",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "Process exited code=exited, status=0/SUCCESS (previously status=2/INVALIDARGUMENT)."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "cat /etc/shutdown-schedule.conf",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "MON_WED_HOUR=21, THU_SUN_HOUR=22, MORNING_END_HOUR=5 — confirmed unchanged from original, lenience-block check confirmed intact in source diff."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"risks": [
|
||||||
|
"Redeploying re-runs the full setup script (chattr -i/+i, systemd daemon-reload, service restarts) on a live system; verified no other unrelated drift was introduced by diffing against the pre-change file.",
|
||||||
|
"Did not test the actual hibernate/rtcwake branch end-to-end (would require simulating an alarm-day shutdown), only confirmed syntax validity and that the script reaches/exits the case statement without crashing."
|
||||||
|
],
|
||||||
|
"rollback": [
|
||||||
|
"git revert this commit, then re-run `sudo chattr -i setup_midnight_shutdown.sh && sudo ./setup_midnight_shutdown.sh enable` to redeploy the prior (broken) version.",
|
||||||
|
"After rollback, confirm via `journalctl -t day-specific-shutdown` that the syntax error reappears, then re-apply this fix."
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -720,7 +720,7 @@ Requires=day-specific-shutdown.service
|
|||||||
[Timer]
|
[Timer]
|
||||||
EOF
|
EOF
|
||||||
# Evening hours: from earliest shutdown hour to 23:30
|
# Evening hours: from earliest shutdown hour to 23:30
|
||||||
for hour in $(seq "$earliest_hour" 24); do
|
for hour in $(seq "$earliest_hour" 23); do
|
||||||
printf 'OnCalendar=*-*-* %02d:00:00\n' "$hour"
|
printf 'OnCalendar=*-*-* %02d:00:00\n' "$hour"
|
||||||
printf 'OnCalendar=*-*-* %02d:30:00\n' "$hour"
|
printf 'OnCalendar=*-*-* %02d:30:00\n' "$hour"
|
||||||
done
|
done
|
||||||
@ -940,12 +940,12 @@ if [[ $should_shutdown == true ]]; then
|
|||||||
# inhibitor — a game, Steam, a video player, or our own controller idle-off
|
# inhibitor — a game, Steam, a video player, or our own controller idle-off
|
||||||
# watcher — silently denies the hibernate ("Operation denied due to active
|
# watcher — silently denies the hibernate ("Operation denied due to active
|
||||||
# block inhibitor") and the PC stays up all night. -i overrides all locks.
|
# block inhibitor") and the PC stays up all night. -i overrides all locks.
|
||||||
tomorrow_dow=\$(date -d "tomorrow" +%u)
|
tomorrow_dow=$(date -d "tomorrow" +%u)
|
||||||
case "\$tomorrow_dow" in
|
case "$tomorrow_dow" in
|
||||||
1|5|6|7)
|
1|5|6|7)
|
||||||
wake_epoch=\$(( \$(printf '%(%s)T' -1) + 8 * 3600 ))
|
wake_epoch=$(( $(printf '%(%s)T' -1) + 8 * 3600 ))
|
||||||
logger -t day-specific-shutdown "Tomorrow is alarm day (dow=\$tomorrow_dow) — hibernating, RTC wake at epoch \$wake_epoch"
|
logger -t day-specific-shutdown "Tomorrow is alarm day (dow=$tomorrow_dow) — hibernating, RTC wake at epoch $wake_epoch"
|
||||||
/usr/bin/sudo /usr/sbin/rtcwake -m no -t "\$wake_epoch"
|
/usr/bin/sudo /usr/sbin/rtcwake -m no -t "$wake_epoch"
|
||||||
/usr/bin/systemctl hibernate -i
|
/usr/bin/systemctl hibernate -i
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user