Wait for the actual Stay Awake launcher
This commit is contained in:
1 parent
978dffaa3e
commit
d41ca88f76
2 files changed
+12
-8
No files matched your search
@@ -93,6 +93,7 @@ stop() {
|
|||||||
|
|
||||||
start() {
|
start() {
|
||||||
local idle_owner="$$:$RANDOM:$RANDOM"
|
local idle_owner="$$:$RANDOM:$RANDOM"
|
||||||
|
local launcher_pid=""
|
||||||
|
|
||||||
stop
|
stop
|
||||||
mkdir -p "$state_dir"
|
mkdir -p "$state_dir"
|
||||||
@@ -116,16 +117,19 @@ start() {
|
|||||||
if (( EUID == 0 )); then
|
if (( EUID == 0 )); then
|
||||||
( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&-
|
( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&-
|
||||||
exec "${hold_command[@]}" ) &
|
exec "${hold_command[@]}" ) &
|
||||||
|
launcher_pid=$!
|
||||||
elif [[ -t 0 ]]; then
|
elif [[ -t 0 ]]; then
|
||||||
/usr/bin/sudo -N -b -- "${hold_command[@]}"
|
/usr/bin/sudo -N -b -- "${hold_command[@]}"
|
||||||
else
|
else
|
||||||
( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&-
|
( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&-
|
||||||
exec pkexec "${hold_command[@]}" ) &
|
exec pkexec "${hold_command[@]}" ) &
|
||||||
|
launcher_pid=$!
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For graphical authentication the launcher may wait for a password. Wait for
|
# For graphical authentication the launcher may wait for a password. Wait for
|
||||||
# either the user-owned held command to become ready or the launcher to fail.
|
# either the user-owned held command to become ready or the launcher to fail.
|
||||||
local launcher_pid=${!:-}
|
# sudo -b backgrounds internally, so Bash has no launcher PID in the TTY path;
|
||||||
|
# $! there can still refer to a completed startup process substitution.
|
||||||
local readiness_attempts=0
|
local readiness_attempts=0
|
||||||
while [[ ! -s $inhibit_pid_file ]]; do
|
while [[ ! -s $inhibit_pid_file ]]; do
|
||||||
if [[ -n $launcher_pid ]] && ! kill -0 "$launcher_pid" 2>/dev/null; then
|
if [[ -n $launcher_pid ]] && ! kill -0 "$launcher_pid" 2>/dev/null; then
|
||||||
|
|||||||
@@ -141,18 +141,18 @@ if (( EUID != 0 )); then
|
|||||||
pkexec_marker="$test_tmp/pkexec-used"
|
pkexec_marker="$test_tmp/pkexec-used"
|
||||||
terminal_inhibit_pid_file="$test_tmp/terminal-inhibit-pid"
|
terminal_inhibit_pid_file="$test_tmp/terminal-inhibit-pid"
|
||||||
write_stub pkexec '[[ -z ${PKEXEC_MARKER:-} ]] || touch "$PKEXEC_MARKER"; exec "$@"'
|
write_stub pkexec '[[ -z ${PKEXEC_MARKER:-} ]] || touch "$PKEXEC_MARKER"; exec "$@"'
|
||||||
|
write_stub systemd-inhibit 'sleep 0.2; while [[ $1 == --* ]]; do shift; done; exec "$@"'
|
||||||
|
|
||||||
# start leaves the inhibitor running on purpose, but script tears the pty down
|
# sudo -b returns before its child is ready. Require start to wait for the
|
||||||
# the moment its command returns, which SIGHUPs that inhibitor before it can
|
# delayed child and succeed, then stop it before script tears down the PTY.
|
||||||
# exec. Keep the session open from the inside until the stub has logged.
|
|
||||||
terminal_driver="$test_tmp/terminal-stay-awake"
|
terminal_driver="$test_tmp/terminal-stay-awake"
|
||||||
cat >"$terminal_driver" <<'SH'
|
cat >"$terminal_driver" <<'SH'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
omarchy-update-stay-awake start
|
omarchy-update-stay-awake start
|
||||||
for _ in {1..200}; do
|
[[ -s $XDG_RUNTIME_DIR/omarchy-update-stay-awake/inhibit-pid ]]
|
||||||
grep -q -- '^sudo -N -b -- ' "$SUDO_LOG" && break
|
omarchy-update-stay-awake stop
|
||||||
sleep 0.05
|
[[ ! -e $XDG_RUNTIME_DIR/omarchy-update-stay-awake/inhibit-pid ]]
|
||||||
done
|
|
||||||
SH
|
SH
|
||||||
chmod +x "$terminal_driver"
|
chmod +x "$terminal_driver"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user