From 67c0c9b468664613e9c915df309afaf87f6d90c0 Mon Sep 17 00:00:00 2001 From: Emir Beganovic Date: Mon, 30 Nov 2026 11:33:30 +0100 Subject: [PATCH] Stop boots from freezing after a correct disk password `plymouth ask-for-password` reads the unlock's answer from a pipe with a one-second limit. The initramfs's busybox 1.36.1 drops what it has read when that limit runs out, so an answer that arrives at that moment loses its request number. The rest of it matches no request, and the boot waits forever with the bar at 65%. Put one byte in front of the answer and time only that byte, then read the rest without a limit. A single byte cannot be cut short. With the real scripts under that busybox, and answers 0.97 to 1.00 s into the wait, 120 of 2,400 were lost before and none of 2,400 now. An unlock returns in 2.4 ms, against 2.6 ms. --- default/splash/answer | 3 +- default/splash/plymouth | 7 ++- test/shell.d/boot-splash-answer-test.sh | 61 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100755 test/shell.d/boot-splash-answer-test.sh diff --git a/default/splash/answer b/default/splash/answer index 8e61685ea017..19f61d29765c 100755 --- a/default/splash/answer +++ b/default/splash/answer @@ -19,7 +19,8 @@ exec 3<&0 exec 3<&- "$@" status=$? - printf '%s %s\n' "$id" "$status" >"$run/result" + # The dot is the byte ask-for-password waits for with a time limit. + printf '.%s %s\n' "$id" "$status" >"$run/result" exit "$status" ) <&3 & attempt=$! diff --git a/default/splash/plymouth b/default/splash/plymouth index cfccae713370..3cbf7ce972a3 100755 --- a/default/splash/plymouth +++ b/default/splash/plymouth @@ -96,9 +96,14 @@ ask_for_password() { # session), and ends when the splash is gone for good. An attempt the # splash started is waited for even then: the console's own attempt would # find the volume it unlocked already open, and fail forever. + # + # Only the byte in front of the answer is read with a time limit: busybox's + # read drops what it has read when its time runs out, and an answer cut + # short would leave the boot waiting forever. status="" while [ -z "$status" ]; do - if read -r -t 1 -u 3 reply answer; then + if read -r -t 1 -n 1 -u 3 _; then + read -r -u 3 reply answer [ "$reply" = "$id" ] && status=$answer elif ! alive "$run/session.pid" && ! answering "$id"; then exec 3>&- diff --git a/test/shell.d/boot-splash-answer-test.sh b/test/shell.d/boot-splash-answer-test.sh new file mode 100755 index 000000000000..0aa7a8fdeb58 --- /dev/null +++ b/test/shell.d/boot-splash-answer-test.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +# An unlock's exit status always reaches the `plymouth ask-for-password` that +# waits for it. The initramfs's busybox drops what `read -t` has read when its +# time runs out, so a timed read of more than one byte can lose the start of an +# answer. The timed read here loses the first byte it is sent that way once. + +test_tmp=$(mktemp -d) +run=$test_tmp/run +mkdir "$run" +sleep 60 >/dev/null & +session=$! +trap 'kill "$session" 2>/dev/null || true; rm -rf "$test_tmp"' EXIT +echo "$session" >"$run/session.pid" +touch "$run/ready" + +for script in plymouth answer; do + sed -e "s|/run/omarchy-splash|$run|g" -e 's|read -r -t 1|timed_read|' \ + "$ROOT/default/splash/$script" >"$test_tmp/$script" +done +grep -q timed_read "$test_tmp/plymouth" || fail "the wait for an answer reads with a time limit" + +cat >"$test_tmp/timed-read.sh" <<'SH' +timed_read() { + if [[ $1 == "-n" ]]; then + read -r -t 1 "$@" + elif [[ ! -e $CUT ]]; then + IFS= read -r -t 1 -N 1 -u 3 _ && : >"$CUT" + return 1 + else + read -r -t 1 "$@" + fi +} +SH + +# Asks for a password whose unlock exits with status $1, and prints the status +# ask-for-password gives the hook. +ask() { + local status=0 asking + rm -f "$test_tmp/cut" + CUT=$test_tmp/cut BASH_ENV=$test_tmp/timed-read.sh timeout 10 \ + bash "$test_tmp/plymouth" ask-for-password --command="exit-with $1" --number-of-tries=1 >/dev/null & + asking=$! + for _ in {1..250}; do + [[ ! -s $run/request ]] || break + sleep 0.02 + done + timeout 10 bash "$test_tmp/answer" "$(sed -n 's/^id=//p' "$run/request")" bash -c "exit $1"