Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions default/splash/hold
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ wait_for_session() {

mapfile -t nodes < <(splash_devices)
if (( ${#nodes[@]} == 0 )); then
echo "the splash has no display open"
exit 1
session=$(cat /run/omarchy-splash/session.pid 2>/dev/null || true)
if [[ -n $session ]] && kill -0 "$session" 2>/dev/null; then
echo "the splash is running but has no display open; nothing to hold" >&2
else
echo "the splash is no longer running; nothing to hold" >&2
fi
systemd-notify --ready
exit 0
fi

# A compositor takes a device through logind, which opens it, then reads the
Expand Down
5 changes: 4 additions & 1 deletion default/splash/session
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,22 @@ has_connectors() {
wait_native() {
i=0
find_cards
while [ -z "$native" ] && [ "$i" -lt "$1" ]; do
while [ -z "$native" ] && [ ! -e "$run/stopping" ] && [ "$i" -lt "$1" ]; do
sleep 0.1
i=$((i + 1))
find_cards
done
}

wait_native 80
[ ! -e "$run/stopping" ] || exit 0
devices=${native:-$firmware}
if [ -z "$devices" ]; then
echo "omarchy-splash: no display to draw on"
exit 1
fi
echo "omarchy-splash: drawing on $devices"
touch "$run/starting"

# amdgpu powers a GPU down once no display is connected to it, and a GPU that
# is powered down misses a display plugged in later. The GPUs stay powered
Expand Down Expand Up @@ -168,6 +170,7 @@ esac
while :; do
seatd-launch -- sway $debug --config /usr/lib/omarchy-splash/sway.conf
status=$?
rm -f "$run/ready"
if [ -e "$run/stopping" ] || [ -e "$run/dismissed" ] || [ "$devices" != "$firmware" ]; then
exit "$status"
fi
Expand Down
18 changes: 17 additions & 1 deletion etc/initcpio/hooks/omarchy-splash
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ asks_passphrase() {
# screen, a console login or an emergency shell, with the copy of `stop` the
# real root has: the initramfs's own is gone by then.
run_latehook() {
local run=/run/omarchy-splash session target
local run=/run/omarchy-splash session target i

# A volume asks_passphrase finds asks on the console while the real root
# boots, which the splash would cover.
Expand All @@ -52,6 +52,22 @@ run_latehook() {
return 0
fi

# switch_root deletes the initramfs and moves /dev and /sys away, so a splash
# that has not finished starting cannot finish afterwards. Wait for one that
# has already picked a display; one still waiting for a native GPU (or that
# died before coming up) is taken down instead of stalling the boot.
if [ ! -e "$run/ready" ] && [ -e "$run/starting" ]; then
i=0
while [ ! -e "$run/ready" ] && kill -0 "$session" 2>/dev/null && [ "$i" -lt 50 ]; do
sleep 0.1
i=$((i + 1))
done
fi
if [ ! -e "$run/ready" ] || ! kill -0 "$session" 2>/dev/null; then
/usr/lib/omarchy-splash/stop
return 0
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
fi

# The real root keeps the /dev/shm the session mounted as its own.
rm -f "$run/shm"

Expand Down
44 changes: 44 additions & 0 deletions test/shell.d/boot-splash-hold-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,47 @@ mkfifo "$test_tmp/events"
out=$(holder_waits "$test_tmp/events" 1) || fail "the holder lets go at its time limit when no session comes" "still holding after 5 s"
[[ $out == *"no session took"* ]] || fail "the holder lets go at its time limit when no session comes" "$out"
pass "the holder lets go at its time limit when no session comes"

# When the splash already exited before hold starts (e.g. Escape or simpledrm
# unbind in the real root), hold notifies systemd and exits 0 without creating
# the adoption marker.
fake_bin=$test_tmp/bin
hold_fixture=$test_tmp/hold
mkdir -p "$fake_bin"
sed -e "s|/run/omarchy-splash-hold/adopt|$adopt|g" \
-e "s|/run/omarchy-splash/session.pid|$test_tmp/session.pid|g" \
"$hold" >"$hold_fixture"
grep -qF "$adopt" "$hold_fixture" || fail "hold fixture writes its adoption marker in the test dir"
cat >"$fake_bin/pidof" <<'SH'
#!/bin/bash
exit 1
SH
cat >"$fake_bin/systemd-notify" <<SH
#!/bin/bash
printf '%s\n' "\$*" >"$test_tmp/notified"
SH
chmod +x "$fake_bin/pidof" "$fake_bin/systemd-notify"
rm -f "$adopt" "$test_tmp/notified" "$test_tmp/session.pid"
out=$(PATH="$fake_bin:$PATH" bash "$hold_fixture" 2>&1) ||
fail "hold exits 0 when the splash is no longer running" "$out"
[[ $out == *"the splash is no longer running; nothing to hold"* ]] ||
fail "hold logs when the splash is no longer running" "$out"
[[ $(cat "$test_tmp/notified" 2>/dev/null) == "--ready" ]] ||
fail "hold notifies systemd --ready before exiting when nothing is held" "$(cat "$test_tmp/notified" 2>/dev/null)"
[[ ! -e $adopt ]] ||
fail "hold does not create the adoption marker when nothing is held"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
sleep 10 &
live_session=$!
echo "$live_session" >"$test_tmp/session.pid"
rm -f "$adopt" "$test_tmp/notified"
out=$(PATH="$fake_bin:$PATH" bash "$hold_fixture" 2>&1) ||
fail "hold exits 0 when the splash is running without a display" "$out"
kill "$live_session" 2>/dev/null || true
wait "$live_session" 2>/dev/null || true
[[ $out == *"the splash is running but has no display open; nothing to hold"* ]] ||
fail "hold distinguishes a running splash with no open display" "$out"
[[ $(cat "$test_tmp/notified" 2>/dev/null) == "--ready" ]] ||
fail "hold notifies systemd --ready for a running splash with no open display" "$(cat "$test_tmp/notified" 2>/dev/null)"
[[ ! -e $adopt ]] ||
fail "hold does not create the adoption marker for a running splash with no open display"
pass "hold notifies systemd and exits 0 when the splash has no display open"
63 changes: 63 additions & 0 deletions test/shell.d/boot-splash-session-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,66 @@ signalled=$(sh -c '. "$1"; pidof() { echo 1 2 3; }; kill() { echo "$2"; }; signa
[[ $signalled == "1 2 " ]] ||
fail "stop signals the splash's processes in the initramfs and the real root, and no unit's" "signalled: $signalled"
pass "stop signals the splash's processes in the initramfs and the real root, and no unit's"

# The late hook waits for a splash that has already picked a display to finish
# starting before switch_root deletes the initramfs under it, and takes down a
# splash that is still waiting for a GPU or died before coming up.
late_root=$test_tmp/late
late_hook=$test_tmp/late-hook.sh
sed -e "s|/run/omarchy-splash|$late_root/run/omarchy-splash|g" \
-e "s|/run/systemd/system|$late_root/run/systemd/system|g" \
-e "s|/sysroot/etc/crypttab|$late_root/sysroot/etc/crypttab|g" \
-e "s|/usr/lib/omarchy-splash/stop|$late_root/stop|g" \
-e "s|/etc/systemd/system/omarchy-splash-hold.service|$late_root/etc/omarchy-splash-hold.service|g" \
"$ROOT/etc/initcpio/hooks/omarchy-splash" >"$late_hook"
grep -qF "$late_root/run/omarchy-splash" "$late_hook" || fail "late hook reads its state from the fixture"

reset_late() {
rm -rf "$late_root"
mkdir -p "$late_root/run/omarchy-splash" "$late_root/sysroot/etc" "$late_root/etc"
cat >"$late_root/stop" <<SH
#!/bin/sh
touch "$late_root/stopped"
SH
chmod +x "$late_root/stop"
}

# Case 1: splash already picked a display and writes ready shortly after.
reset_late
sleep 10 &
bg_pid=$!
echo "$bg_pid" >"$late_root/run/omarchy-splash/session.pid"
touch "$late_root/run/omarchy-splash/starting"
(sleep 0.2 && touch "$late_root/run/omarchy-splash/ready") &
ready_writer=$!
sh -c '. "$1" && run_latehook' sh "$late_hook"
wait "$ready_writer" 2>/dev/null || true
kill "$bg_pid" 2>/dev/null || true
wait "$bg_pid" 2>/dev/null || true
[[ ! -e "$late_root/stopped" && -L "$late_root/run/systemd/system/graphical.target.wants/omarchy-splash-hold.service" ]] ||
fail "late hook waits for a starting splash to become ready and schedules hold"
pass "late hook waits for a starting splash to become ready and schedules hold"

# Case 2: splash is still waiting for a native GPU (no starting marker).
reset_late
sleep 10 &
bg_pid=$!
echo "$bg_pid" >"$late_root/run/omarchy-splash/session.pid"
sh -c '. "$1" && run_latehook' sh "$late_hook"
kill "$bg_pid" 2>/dev/null || true
wait "$bg_pid" 2>/dev/null || true
[[ -e "$late_root/stopped" && ! -e "$late_root/run/systemd/system/graphical.target.wants/omarchy-splash-hold.service" ]] ||
fail "late hook stops a splash still waiting for a GPU instead of stalling boot"
pass "late hook stops a splash still waiting for a GPU instead of stalling boot"

# Case 3: splash picked a display, then died before writing ready.
reset_late
(sleep 0.15) &
bg_pid=$!
echo "$bg_pid" >"$late_root/run/omarchy-splash/session.pid"
touch "$late_root/run/omarchy-splash/starting"
sh -c '. "$1" && run_latehook' sh "$late_hook"
wait "$bg_pid" 2>/dev/null || true
[[ -e "$late_root/stopped" && ! -e "$late_root/run/systemd/system/graphical.target.wants/omarchy-splash-hold.service" ]] ||
fail "late hook stops cleanly when a starting splash exits before ready"
pass "late hook stops cleanly when a starting splash exits before ready"