Skip binfmt_misc register when unnecessary (#693)

This improves commit 6dc45a80e764eacd6e311c32164b623bbe7f8e08

Check if interpreter is already registered before running the register
step. This avoids unnecessary "sudo" execution which may require user
interaction for the password.

Improves on #685
This commit is contained in:
Stefan Becker 2023-05-09 16:24:49 +03:00 committed by GitHub
parent 47eee1f0dd
commit 01d24ef227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,13 +132,15 @@ if [[ "${binfmt_misc_required}" == "1" ]]; then
fi fi
echo "binfmt_misc mounted" echo "binfmt_misc mounted"
fi fi
# Register qemu-arm for binfmt_misc (binfmt_misc won't care duplicate entries unless they have common names) if ! grep -q "^interpreter ${qemu_arm}" /proc/sys/fs/binfmt_misc/qemu-arm* ; then
reg="echo ':qemu-arm-rpi:M::"\ # Register qemu-arm for binfmt_misc
reg="echo ':qemu-arm-rpi:M::"\
"\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:"\ "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:"\
"\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:"\ "\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:"\
"$qemu_arm:F' > /proc/sys/fs/binfmt_misc/register" "${qemu_arm}:F' > /proc/sys/fs/binfmt_misc/register"
echo "Registering qemu-arm for binfmt_misc..." echo "Registering qemu-arm for binfmt_misc..."
sudo bash -c "$reg" 2>/dev/null || true sudo bash -c "${reg}" 2>/dev/null || true
fi
fi fi
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${DOCKER_CMDLINE_NAME}' SIGINT SIGTERM trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${DOCKER_CMDLINE_NAME}' SIGINT SIGTERM