scripts/qemu-binfmt-conf.sh: allow clearing of entries
PATCH 1/1 scripts/qemu-binfmt-conf.sh: allow clearing of entries
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.
--- scripts/qemu-binfmt-conf.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
scripts/qemu-binfmt-conf.sh +14 -2
@@ -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 ;;
Signature · 1 line
2.17.1
Le 03/07/2018 à 18:00, Alex Bennée a écrit :
Quoted 31 lines
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 <[email protected]>--- scripts/qemu-binfmt-conf.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)scripts/qemu-binfmt-conf.sh +2
-1@@ -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 :
scripts/qemu-binfmt-conf.sh qemu_register_interpreter() { · line 254
Quoted 5 lines
scripts/qemu-binfmt-conf.sh +2
-0@@ -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
You should use qemu_check_access()
Quoted 19 lines
scripts/qemu-binfmt-conf.sh +6
-1+ 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
scripts/qemu-binfmt-conf.sh while true ; do · line 371
Quoted 10 lines
scripts/qemu-binfmt-conf.sh +4
-0@@ -354,6 +362,10 @@ while true ; do FLAGS="" fi ;; + --clear) + shift + BINFMT_SET=qemu_clear_interpreter + ;; *) break ;;
if you use --debian or --systemd, you don't have the problem because update-binfmts and systemd-binfmt.service update /proc from the generated files for you.
But you're right there is no command to undo what we have done. You manage only the /proc case, I think it would be also useful to remove the files from $EXPORTDIR.
So could you also manage something like "--debian --clear" and "--systemd CPU --clear"?
Thanks,
Laurent
Quoted 65 lines · Laurent Vivier
Quoted 31 lines · Alex Bennée
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 <[email protected]>--- scripts/qemu-binfmt-conf.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)scripts/qemu-binfmt-conf.sh +2
-1@@ -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 :scripts/qemu-binfmt-conf.sh qemu_register_interpreter() { · line 254
Quoted 5 lines
scripts/qemu-binfmt-conf.sh +2
-0@@ -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 ]; thenYou should use
qemu_check_access()Quoted 25 lines
scripts/qemu-binfmt-conf.sh +10
-1+ 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 + ;;
Quoted 8 lines
scripts/qemu-binfmt-conf.sh while true ; do · line 371
Quoted 4 lines
scripts/qemu-binfmt-conf.sh +0
-0*) break ;;if you use --debian or --systemd, you don't have the problem because update-binfmts and systemd-binfmt.service update /proc from the generated files for you.
Usually I just "apt install qemu-user" and be done with it but I was writing up a blog post and trying to keep it as distro agnostic as possible.
Quoted 7 lines
But you're right there is no command to undo what we have done. You manage only the /proc case, I think it would be also useful to remove the files from $EXPORTDIR.
So could you also manage something like "--debian --clear" and "--systemd CPU --clear"?
Sure, I'll look into it.
Quoted 3 lines
Thanks,
Laurent
--
Alex Bennée
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] scripts/qemu-binfmt-conf.sh: allow clearing of entries
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'b09b364445 scripts/qemu-binfmt-conf.sh: allow clearing of entries
=== OUTPUT BEGIN ===
Checking PATCH 1/1: scripts/qemu-binfmt-conf.sh: allow clearing of entries...
WARNING: line over 80 characters
#25: FILE: scripts/qemu-binfmt-conf.sh:167:
+ [--help][--clear][--credential yes|no][--exportdir PATH]
ERROR: line over 90 characters
#56: FILE: scripts/qemu-binfmt-conf.sh:317:
+options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,clear,credential: -- "$@")
total: 1 errors, 1 warnings, 46 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]