Skip to content

Commit

Permalink
Fix RAUC tryboot handler set-state idempotency, add more checks (#3891)
Browse files Browse the repository at this point in the history
When RPi is booted in the tryboot state and the set-state operation is called
for the second time, the tryboot files don't exists anymore and the handler
exits with an error code, printing an error in the Supervisor logs. Fix
handling of this case and add few more checks to make the handler a bit more
robust/traceable.
  • Loading branch information
sairon authored Feb 24, 2025
1 parent 8531e7b commit 56e3a37
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ case "$1" in
slot_bootname="$2"
new_state="$3"
echo "tryboot set-state $slot_bootname $new_state" >&2
if [ "${new_state}" = "good" ]; then
touch "${boot_dir}/slot-${slot_bootname}/.good"
else

if [ "${new_state}" != "good" ]; then
rm -f "${boot_dir}/slot-${slot_bootname}/.good"
exit 0
fi
Expand All @@ -85,6 +84,20 @@ case "$1" in

# Check if tryboot is active
if ! cmp -s -n 4 /proc/device-tree/chosen/bootloader/tryboot /dev/zero; then
if [ ! -f "${boot_dir}/cmdline-tryboot.txt" ]; then
if [ -f "${boot_dir}/slot-${slot_bootname}/.good" ]; then
# Most probably already handled on this boot before, do nothing
exit 0
else
echo "cmdline-tryboot.txt not found, can't commit current state." >&2
exit 1
fi
fi
# tryboot.txt MUST exist at this point
if [ ! -f "${boot_dir}/tryboot.txt" ]; then
echo "tryboot.txt not found, can't commit current state." >&2
exit 1
fi
cmdline_tryboot=$(head -n1 "${boot_dir}/cmdline-tryboot.txt")
tryboot_slot=$(get_value rauc.slot "${cmdline_tryboot}")
if [ "${tryboot_slot}" != "${slot_bootname}" ]; then
Expand All @@ -98,6 +111,10 @@ case "$1" in
rm "${boot_dir}/tryboot.txt"
rm /run/systemd/reboot-param
fi

if [ "${new_state}" = "good" ]; then
touch "${boot_dir}/slot-${slot_bootname}/.good"
fi
;;

get-current)
Expand Down

0 comments on commit 56e3a37

Please sign in to comment.