Currently running the script twice will fail with "sh: echo: I/O error" as the registration is already complete. Add a new option --clear to reset the entries to save the user doing it by hand.
Signed-off-by: Alex Bennée <alex.ben...@linaro.org> --- scripts/qemu-binfmt-conf.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index d7eefda0b8..13ef4713e6 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -160,7 +160,7 @@ qemu_get_family() { usage() { cat <<EOF Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] - [--help][--credential yes|no][--exportdir PATH] + [--help][--clear][--credential yes|no][--exportdir PATH] Configure binfmt_misc to use qemu interpreter @@ -176,6 +176,7 @@ Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] (default: $SYSTEMDDIR or $DEBIANDIR) --credential: if yes, credential and security tokens are calculated according to the binary to interpret + --clear: clear existing qemu binfmt registrations To import templates with update-binfmts, use : @@ -249,6 +250,13 @@ qemu_register_interpreter() { qemu_generate_register > /proc/sys/fs/binfmt_misc/register } +qemu_clear_interpreter() { + if [ -e /proc/sys/fs/binfmt_misc/qemu-$cpu ]; then + echo "Removing qemu-$cpu as binfmt interpreter for $cpu" + echo -1 > /proc/sys/fs/binfmt_misc/qemu-$cpu + fi +} + qemu_generate_systemd() { echo "Setting $qemu as binfmt interpreter for $cpu for systemd-binfmt.service" qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" @@ -302,7 +310,7 @@ DEBIANDIR="/usr/share/binfmts" QEMU_PATH=/usr/local/bin FLAGS="" -options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@") +options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,clear,credential: -- "$@") eval set -- "$options" while true ; do @@ -354,6 +362,10 @@ while true ; do FLAGS="" fi ;; + --clear) + shift + BINFMT_SET=qemu_clear_interpreter + ;; *) break ;; -- 2.17.1