bootctl: Fix update not adding EFI entry if Boot IDs are non-consecutive
authorAnssi Hannula <anssi.hannula@bitwise.fi>
Thu, 23 Sep 2021 09:08:05 +0000 (12:08 +0300)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 12 Oct 2021 15:07:12 +0000 (17:07 +0200)
commit0028a3eb976dfa7209433dfa3a24b785f05fd352
tree587ddbd2984b0eb5a00614683a5c1e70aabea1b4
parentdd6cb364bcc58b390671d4ee2ed7b30f4a5dced8
bootctl: Fix update not adding EFI entry if Boot IDs are non-consecutive

"bootctl update" tries to add sd-boot to the EFI boot loader list if it
is not already there. To do so, it uses find_slot() which finds the
proper BootXXXX slot ID to use and also returns 1 if an existing sd-boot
entry was found at this ID or 0 if it is a new unused ID. In "update"
case install_variables() only writes the entry in case 0 (no existing
entry).

However, find_slot() erroneously returns 1 if it finds a gap in the Boot
IDs (i.e. when not resorting to max(ids) + 1). This causes
"bootctl update" to not add a missing systemd-boot boot entry if the
existing BootXXXX entry IDs are not consecutive.

Fix that by returning 0 in find_slot() when an empty gap ID is selected
to make it match the behavior when selecting an empty non-gap ID.

(cherry picked from commit 26d54e1263dcb58daa6578595cc6ab1037315593)
src/boot/bootctl.c