From db2e2b26f75c30f2dd0b626f4d6368beb63c797f Mon Sep 17 00:00:00 2001 From: ya-luotao Date: Sat, 22 Aug 2026 02:25:32 +0800 Subject: [PATCH 1/3] Install system-sleep hooks executable so systemd runs them omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu copied the keyboard-backlight and force-igpu hooks into /usr/lib/systemd/system-sleep/ with cp -p, preserving the source's 644 mode. systemd-sleep only executes executable files in that directory, so both hooks were silently skipped. Use install -m755 so the installed hooks are executable regardless of the source mode, and mark the hooks executable in the repo as well. Fixes #7618 Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF --- bin/omarchy-hibernation-setup | 2 +- bin/omarchy-toggle-hybrid-gpu | 2 +- default/systemd/system-sleep/force-igpu | 0 default/systemd/system-sleep/keyboard-backlight | 0 4 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 default/systemd/system-sleep/force-igpu mode change 100644 => 100755 default/systemd/system-sleep/keyboard-backlight diff --git a/bin/omarchy-hibernation-setup b/bin/omarchy-hibernation-setup index 7bc5724679b7..4889511e6292 100755 --- a/bin/omarchy-hibernation-setup +++ b/bin/omarchy-hibernation-setup @@ -89,7 +89,7 @@ echo "Adding resume hook to $MKINITCPIO_CONF" echo "HOOKS+=(resume)" | sudo tee "$MKINITCPIO_CONF" >/dev/null # Ensure keyboard backlight doesn't prevent sleep -sudo cp -p "$OMARCHY_PATH/default/systemd/system-sleep/keyboard-backlight" /usr/lib/systemd/system-sleep/ +sudo install -m755 "$OMARCHY_PATH/default/systemd/system-sleep/keyboard-backlight" /usr/lib/systemd/system-sleep/ # Add resume= kernel parameters so the initramfs resume hook knows where to find the # hibernation image. Without these, resume happens late (after GPU drivers load) and fails. diff --git a/bin/omarchy-toggle-hybrid-gpu b/bin/omarchy-toggle-hybrid-gpu index aa7c0582586f..d8a23c25484d 100755 --- a/bin/omarchy-toggle-hybrid-gpu +++ b/bin/omarchy-toggle-hybrid-gpu @@ -60,7 +60,7 @@ case "$gpu_mode" in # Force igpu mode after system sleep (or dgpu could get activated) sudo mkdir -p /usr/lib/systemd/system-sleep - sudo cp -p "$OMARCHY_PATH/default/systemd/system-sleep/force-igpu" /usr/lib/systemd/system-sleep/ + sudo install -m755 "$OMARCHY_PATH/default/systemd/system-sleep/force-igpu" /usr/lib/systemd/system-sleep/ # Delay supergfxd startup to avoid race condition with display manager # that can cause system freeze when booting in Integrated mode diff --git a/default/systemd/system-sleep/force-igpu b/default/systemd/system-sleep/force-igpu old mode 100644 new mode 100755 diff --git a/default/systemd/system-sleep/keyboard-backlight b/default/systemd/system-sleep/keyboard-backlight old mode 100644 new mode 100755 From 8e5ed6ffc10f631d5f692e29eba8b6c543e11ad0 Mon Sep 17 00:00:00 2001 From: ya-luotao Date: Sat, 22 Aug 2026 07:45:27 +0800 Subject: [PATCH 2/3] Repair already-installed system-sleep hooks with a migration Installing the hooks with install -m755 only helps machines that run hibernation setup or the GPU toggle again, and neither path reaches the install on an affected machine: hibernation setup exits early once the resume hook is configured, and the GPU toggle only installs force-igpu when switching into Integrated mode, which is the mode those users are already in. Make the installed copies executable in place instead. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF --- migrations/1787336732.sh | 15 ++++ .../sleep-hook-executable-migration-test.sh | 82 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 migrations/1787336732.sh create mode 100644 test/shell.d/sleep-hook-executable-migration-test.sh diff --git a/migrations/1787336732.sh b/migrations/1787336732.sh new file mode 100644 index 000000000000..fe32d293a95a --- /dev/null +++ b/migrations/1787336732.sh @@ -0,0 +1,15 @@ +echo "Make installed system-sleep hooks executable so systemd runs them" + +sleep_hook_dir="${OMARCHY_SYSTEM_SLEEP_DIR:-/usr/lib/systemd/system-sleep}" + +# omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu copied these hooks +# into place with cp -p from a 644 source, and systemd-sleep(8) silently skips +# non-executable files here. Only the mode is wrong, so fix the mode in place: +# a hook that is absent or already executable is left alone, which also makes +# the second user's run on the same machine a no-op. +for hook in keyboard-backlight force-igpu; do + path="$sleep_hook_dir/$hook" + if [[ -f $path && ! -x $path ]]; then + sudo chmod 755 "$path" + fi +done diff --git a/test/shell.d/sleep-hook-executable-migration-test.sh b/test/shell.d/sleep-hook-executable-migration-test.sh new file mode 100644 index 000000000000..a6180d60831c --- /dev/null +++ b/test/shell.d/sleep-hook-executable-migration-test.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +set -euo pipefail + +source "$(dirname "$0")/base-test.sh" + +migration="$ROOT/migrations/1787336732.sh" +test_dir=$(mktemp -d) +trap 'rm -rf "$test_dir"' EXIT + +mkdir -p "$test_dir/bin" "$test_dir/system-sleep" + +# sudo runs the real command, so chmod acts on the redirected hook directory. +cat >"$test_dir/bin/sudo" <<'STUB' +#!/bin/bash + +printf 'sudo %s\n' "$*" >>"$CALLS" +exec "$@" +STUB + +chmod +x "$test_dir/bin/"* + +export CALLS="$test_dir/calls" + +hook_dir="$test_dir/system-sleep" + +install_hook() { + printf '#!/bin/bash\n' >"$hook_dir/$1" + chmod "$2" "$hook_dir/$1" +} + +run_migration() { + : >"$CALLS" + + OMARCHY_SYSTEM_SLEEP_DIR="$hook_dir" \ + PATH="$test_dir/bin:$PATH" \ + bash -euo pipefail "$migration" >/dev/null +} + +# Both hooks used to be copied in with cp -p from a 644 source, so an affected +# machine has non-executable copies that systemd-sleep never runs. +rm -f "$hook_dir"/* +install_hook keyboard-backlight 644 +install_hook force-igpu 644 +run_migration + +[[ -x $hook_dir/keyboard-backlight ]] || fail "migration makes keyboard-backlight executable" +pass "migration makes keyboard-backlight executable" + +[[ -x $hook_dir/force-igpu ]] || fail "migration makes force-igpu executable" +pass "migration makes force-igpu executable" + +grep -qx "sudo chmod 755 $hook_dir/keyboard-backlight" "$CALLS" || + fail "migration changes the mode through sudo" "$(cat "$CALLS")" +pass "migration changes the mode through sudo" + +# Hybrid-mode machines never install force-igpu, and hibernation setup is +# optional, so an absent hook is not an error. +rm -f "$hook_dir"/* +install_hook keyboard-backlight 644 +run_migration + +[[ -x $hook_dir/keyboard-backlight ]] || fail "migration repairs the hooks that are present" +pass "migration repairs the hooks that are present" + +[[ ! -e $hook_dir/force-igpu ]] || fail "migration does not create a missing hook" +pass "migration does not create a missing hook" + +# Migration completion is recorded per user, so a second account runs it again +# on a machine that is already repaired and must not need sudo for nothing. +run_migration + +[[ ! -s $CALLS ]] || + fail "migration touches nothing on an already-repaired machine" "$(cat "$CALLS")" +pass "migration touches nothing on an already-repaired machine" + +rm -f "$hook_dir"/* +run_migration + +[[ ! -s $CALLS ]] || + fail "migration touches nothing when no hook is installed" "$(cat "$CALLS")" +pass "migration touches nothing when no hook is installed" From 5003d6b729e4fd9df4a30e1dfe24e5e2819d0657 Mon Sep 17 00:00:00 2001 From: ya-luotao Date: Sat, 22 Aug 2026 08:00:02 +0800 Subject: [PATCH 3/3] Only activate a stale force-igpu hook in Integrated mode force-igpu switches the GPU back to Integrated after every sleep, so it must only be live on a machine that is still in Integrated mode. The toggle removes the hook on its way to Hybrid, but a mode change made directly through supergfxctl leaves the inert copy behind, and waking it up would flip the GPU under the user. Ask supergfxd the way the toggle does before making that hook executable, and leave it alone when there is no answer. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF --- migrations/1787336732.sh | 32 +++++++++++- .../sleep-hook-executable-migration-test.sh | 49 +++++++++++++++++-- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/migrations/1787336732.sh b/migrations/1787336732.sh index fe32d293a95a..5ecb408ab3fa 100644 --- a/migrations/1787336732.sh +++ b/migrations/1787336732.sh @@ -2,6 +2,27 @@ echo "Make installed system-sleep hooks executable so systemd runs them" sleep_hook_dir="${OMARCHY_SYSTEM_SLEEP_DIR:-/usr/lib/systemd/system-sleep}" +# force-igpu switches the GPU back to Integrated after every sleep, so it may +# only be live on a machine that is still in Integrated mode. The toggle removes +# the hook when it switches to Hybrid, but a mode change made directly through +# supergfxctl leaves the copy behind, and that copy has been inert and must +# stay that way. Ask supergfxd the way the toggle does; no answer means the +# hook is left as it is. +integrated_gpu_mode() { + local attempt mode + + for attempt in {1..3}; do + if mode=$(timeout --kill-after=1s 3s supergfxctl -g 2>/dev/null) && [[ -n $mode ]]; then + [[ $mode == "Integrated" ]] + return + fi + + (( attempt < 3 )) && sleep 1 + done + + return 1 +} + # omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu copied these hooks # into place with cp -p from a 644 source, and systemd-sleep(8) silently skips # non-executable files here. Only the mode is wrong, so fix the mode in place: @@ -9,7 +30,14 @@ sleep_hook_dir="${OMARCHY_SYSTEM_SLEEP_DIR:-/usr/lib/systemd/system-sleep}" # the second user's run on the same machine a no-op. for hook in keyboard-backlight force-igpu; do path="$sleep_hook_dir/$hook" - if [[ -f $path && ! -x $path ]]; then - sudo chmod 755 "$path" + + if [[ ! -f $path || -x $path ]]; then + continue + fi + + if [[ $hook == "force-igpu" ]] && ! integrated_gpu_mode; then + continue fi + + sudo chmod 755 "$path" done diff --git a/test/shell.d/sleep-hook-executable-migration-test.sh b/test/shell.d/sleep-hook-executable-migration-test.sh index a6180d60831c..42638ed75f40 100644 --- a/test/shell.d/sleep-hook-executable-migration-test.sh +++ b/test/shell.d/sleep-hook-executable-migration-test.sh @@ -18,6 +18,16 @@ printf 'sudo %s\n' "$*" >>"$CALLS" exec "$@" STUB +# supergfxd answers with whatever mode the scenario sets, and like a daemon that +# is not running, stays silent when none is set. +cat >"$test_dir/bin/supergfxctl" <<'STUB' +#!/bin/bash + +printf 'supergfxctl %s\n' "$*" >>"$CALLS" +[[ -n ${GPU_MODE:-} ]] || exit 1 +echo "$GPU_MODE" +STUB + chmod +x "$test_dir/bin/"* export CALLS="$test_dir/calls" @@ -42,18 +52,48 @@ run_migration() { rm -f "$hook_dir"/* install_hook keyboard-backlight 644 install_hook force-igpu 644 -run_migration +GPU_MODE=Integrated run_migration [[ -x $hook_dir/keyboard-backlight ]] || fail "migration makes keyboard-backlight executable" pass "migration makes keyboard-backlight executable" -[[ -x $hook_dir/force-igpu ]] || fail "migration makes force-igpu executable" -pass "migration makes force-igpu executable" +[[ -x $hook_dir/force-igpu ]] || fail "migration makes force-igpu executable in Integrated mode" +pass "migration makes force-igpu executable in Integrated mode" + +grep -qx 'supergfxctl -g' "$CALLS" || + fail "migration asks supergfxd for the GPU mode" "$(cat "$CALLS")" +pass "migration asks supergfxd for the GPU mode" grep -qx "sudo chmod 755 $hook_dir/keyboard-backlight" "$CALLS" || fail "migration changes the mode through sudo" "$(cat "$CALLS")" pass "migration changes the mode through sudo" +# force-igpu forces Integrated mode after every sleep. The toggle removes it on +# the way to Hybrid, but a mode change made straight through supergfxctl leaves +# the inert copy behind, and waking it up would flip the GPU under the user. +rm -f "$hook_dir"/* +install_hook keyboard-backlight 644 +install_hook force-igpu 644 +GPU_MODE=Hybrid run_migration + +[[ ! -x $hook_dir/force-igpu ]] || fail "migration leaves force-igpu inert in Hybrid mode" +pass "migration leaves force-igpu inert in Hybrid mode" + +[[ -x $hook_dir/keyboard-backlight ]] || fail "migration still repairs keyboard-backlight in Hybrid mode" +pass "migration still repairs keyboard-backlight in Hybrid mode" + +# With no answer from supergfxd the mode is unknown, so the hook stays as it is. +rm -f "$hook_dir"/* +install_hook force-igpu 644 +run_migration + +[[ ! -x $hook_dir/force-igpu ]] || fail "migration leaves force-igpu inert when supergfxd does not answer" +pass "migration leaves force-igpu inert when supergfxd does not answer" + +(( $(grep -cx 'supergfxctl -g' "$CALLS") == 3 )) || + fail "migration retries the GPU mode query like the toggle does" "$(cat "$CALLS")" +pass "migration retries the GPU mode query like the toggle does" + # Hybrid-mode machines never install force-igpu, and hibernation setup is # optional, so an absent hook is not an error. rm -f "$hook_dir"/* @@ -68,7 +108,8 @@ pass "migration does not create a missing hook" # Migration completion is recorded per user, so a second account runs it again # on a machine that is already repaired and must not need sudo for nothing. -run_migration +install_hook force-igpu 755 +GPU_MODE=Integrated run_migration [[ ! -s $CALLS ]] || fail "migration touches nothing on an already-repaired machine" "$(cat "$CALLS")"