Skip to content

Commit

Permalink
initrdscripts: fsuuidinit: use file based mutex to avoid race condition
Browse files Browse the repository at this point in the history
As soon as the UUID is regenerated udev runs the correspondign rules.

However, the rules expect the new UUID to be cached in a file, so there
is a race condition between the creation of the file and the udev rule.

This commit avoid the race condition by using a file mutex that the
udev rule can wait on.

Change-type: patch
Signed-off-by: Alex Gonzalez <alexg@balena.io>
  • Loading branch information
alexgg committed May 11, 2024
1 parent ef51b29 commit 3f6a302
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ fsuuidsinit_run() {
for dev in /dev/disk/by-state/resin-rootB /dev/disk/by-state/resin-state /dev/disk/by-state/resin-data /dev/disk/by-state/resin-rootA; do
uuid="$(get_dev_uuid "${dev}")"
fstype="$(get_dev_fstype "${dev}")"
if [ "${uuid}" = "$(get_cmdline_root_uuid)" ]; then
touch "/run/initramfs/bootparam_root.mux"
fi
if regenerate_uuid "${dev}" "${fstype}"; then
if [ "${uuid}" = "$(get_cmdline_root_uuid)" ]; then
if [ -f "/run/initramfs/bootparam_root.mux" ]; then
bootparam_root="UUID=$(get_dev_uuid "${dev}")"
echo "${bootparam_root}" > /run/initramfs/bootparam_root
rm -f "/run/initramfs/bootparam_root.mux"
info "Using new root UUID: ${bootparam_root}"
fi
else
Expand Down

0 comments on commit 3f6a302

Please sign in to comment.