Keep a closed lid from suspending during install and update
shellcheck / shellcheck (push) Successful in 19s
shellcheck / shellcheck (push) Successful in 19s
logind ignores sleep locks when the lid closes (LidSwitchIgnoreInhibited), so install.sh and update now also take a handle-lid-switch lock. It's a separate systemd-inhibit, since polkit refuses that lock outside a local session and that mustn't cost the sleep lock too. After a long sleep, a pacman upgrade can be cut off part way and sudo's cached password expires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+7
-3
@@ -83,10 +83,14 @@ on_exit() {
|
||||
trap on_exit EXIT
|
||||
|
||||
# Keep the computer from suspending, from idle or a closed lid, until the
|
||||
# install exits. tail exits with it, and that ends the inhibitor.
|
||||
# install exits. logind ignores sleep locks when the lid closes, so the lid
|
||||
# takes its own lock, kept apart since polkit refuses it outside a local
|
||||
# session. tail exits with the install, and that ends the inhibitors.
|
||||
if command -v systemd-inhibit > /dev/null; then
|
||||
systemd-inhibit --what=sleep:idle --who=CoreDesktop --why="Installing CoreDesktop" --mode=block \
|
||||
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
|
||||
for what in sleep:idle handle-lid-switch; do
|
||||
systemd-inhibit --what="$what" --who=CoreDesktop --why="Installing CoreDesktop" --mode=block \
|
||||
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
|
||||
done
|
||||
fi
|
||||
|
||||
# Lets the install's pacman upgrade the system past the guard that stops
|
||||
|
||||
+3
-1
@@ -65,10 +65,12 @@ ran() {
|
||||
[ "$status" -eq 0 ]
|
||||
# In the background, so give it a moment
|
||||
for _ in 1 2 3 4 5 6 7 8 9 10; do
|
||||
grep -q '^systemd-inhibit ' "$STUB_LOG" && break
|
||||
[ "$(grep -c '^systemd-inhibit ' "$STUB_LOG")" -ge 2 ] && break
|
||||
/usr/bin/sleep 0.1
|
||||
done
|
||||
grep -q '^systemd-inhibit --what=sleep:idle .* --mode=block tail --pid=[0-9]* -f /dev/null$' "$STUB_LOG"
|
||||
# logind ignores sleep locks when the lid closes, so the lid needs its own
|
||||
grep -q '^systemd-inhibit --what=handle-lid-switch .* --mode=block tail --pid=[0-9]* -f /dev/null$' "$STUB_LOG"
|
||||
}
|
||||
|
||||
@test "update's hooks may upgrade past the pacman guard" {
|
||||
|
||||
@@ -153,11 +153,17 @@ SUDO_KEEPALIVE_PID=$!
|
||||
trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null' EXIT
|
||||
|
||||
# Keep the computer from suspending, from idle or a closed lid, until update
|
||||
# exits: a pacman upgrade cut off part way can leave it unbootable. tail exits
|
||||
# with update, and that ends the inhibitor.
|
||||
# exits: a pacman upgrade cut off part way can leave it unbootable, and after a
|
||||
# long sleep sudo's cached password has expired, so the next sudo times out.
|
||||
# logind ignores sleep locks when the lid closes (LidSwitchIgnoreInhibited), so
|
||||
# the lid takes its own lock; it's kept apart because polkit refuses it outside
|
||||
# a local session, and that mustn't lose the sleep lock too. tail exits with
|
||||
# update, and that ends the inhibitors.
|
||||
if command -v systemd-inhibit > /dev/null; then
|
||||
systemd-inhibit --what=sleep:idle --who=CoreDesktop --why="Updating CoreDesktop" --mode=block \
|
||||
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
|
||||
for what in sleep:idle handle-lid-switch; do
|
||||
systemd-inhibit --what="$what" --who=CoreDesktop --why="Updating CoreDesktop" --mode=block \
|
||||
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
|
||||
done
|
||||
fi
|
||||
|
||||
rm -f "$REBOOT_NEEDED"
|
||||
|
||||
Reference in New Issue
Block a user