From 06fff0d777a0586d4ec175321b111a08e4c3f07b Mon Sep 17 00:00:00 2001 From: David Young Date: Sun, 29 Nov 2026 21:25:35 -0700 Subject: [PATCH] Keep a closed lid from suspending during install and update 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 --- install.sh | 10 +++++++--- tests/update.bats | 4 +++- update | 14 ++++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 920455d..f39d7a6 100755 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/tests/update.bats b/tests/update.bats index 6218247..21c2c11 100644 --- a/tests/update.bats +++ b/tests/update.bats @@ -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" { diff --git a/update b/update index 9043b2e..6102fac 100755 --- a/update +++ b/update @@ -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"