From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOv3q-0008NM-Rv for qemu-devel@nongnu.org; Thu, 28 Jan 2016 17:29:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOv3n-0006Mr-Hi for qemu-devel@nongnu.org; Thu, 28 Jan 2016 17:29:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOv3n-0006MO-A6 for qemu-devel@nongnu.org; Thu, 28 Jan 2016 17:29:03 -0500 References: <1454018912-32012-1-git-send-email-laurent@vivier.eu> From: Eric Blake Message-ID: <56AA962D.4070702@redhat.com> Date: Thu, 28 Jan 2016 15:29:01 -0700 MIME-Version: 1.0 In-Reply-To: <1454018912-32012-1-git-send-email-laurent@vivier.eu> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="nXXNWnXGOO8d4qSgCtiBpPMdN7NgqcxEV" Subject: Re: [Qemu-devel] [PATCH v2] linux-user: Original qemu-binfmt-conf.h is only able to write configuration into /proc/sys/fs/binfmt_misc, and the configuration is lost on reboot. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, riku.voipio@linaro.org, mjt@tls.msk.ru, agraf@suse.de This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --nXXNWnXGOO8d4qSgCtiBpPMdN7NgqcxEV Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/28/2016 03:08 PM, Laurent Vivier wrote: Subject line is TOOO long. I suggest: linux-user: Fix qemu-binfmt-conf.h to store config across reboot > This script can configure debian and systemd services to restore > configuration on reboot. Moreover, it is able to manage binfmt > credential and to configure the path of the interpreter. >=20 > diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh > old mode 100644 > new mode 100755 > index 289b1a3..56bc88e > --- a/scripts/qemu-binfmt-conf.sh > +++ b/scripts/qemu-binfmt-conf.sh > @@ -1,72 +1,314 @@ > #!/bin/sh > # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution= by the kernel > =20 > +aarch64_magic=3D'\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x= 00\x02\x00\xb7\x00' > +aarch64_mask=3D'\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\x= ff\xff\xff\xfe\xff\xff\xff' > +aarch64_family=3Darm > + > +qemu_get_family() { > + > +usage() { > + cat < +Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]= > + --credential: if yes, credential an security tokens are s/an/and/ > + echo -n " " 'echo -n' is not portable. Use 'printf' instead. > + for CPU in $qemu_target_list ; > + do > + echo -n "$CPU " and again. > + done > + echo This loop results in trailing whitespace (not fatal, but nice to avoid where possible). Also, using a shell loop is a waste of effort; when you can just do: printf "%s " $qemu_target_list and get the same effect. > +} > + > +qemu_check_access() { > + if [ ! -w "$1" ] ; then > + echo "ERROR: cannot write to $1" 1>&2 > + exit 1 Checking whether a file is writable is often a TOCTTOU race; since you have to handle failures to redirect to the file anyways (in case the file changed between your check and the actual use), can you just skip the check as redundant? > +qemu_check_debian() { > + if [ ! -e /etc/debian_version ] ; then > + echo "WARNING: your system is not a Debian based distro" 1>&2 > + elif ! installed_dpkg binfmt-support ; then > + echo "WARNING: package binfmt-support is needed !" 1>&2 Trailing '!' in error messages is shouting at the user; I tend to avoid them. But if you must use it, in English there is no space between the final word and the punctuation: s/needed !/needed!/ > + fi > + qemu_check_access "$EXPORTDIR" > +} > + > +qemu_check_systemd() { > + if ! systemctl -q is-enabled systemd-binfmt.service ; then > + echo "WARNING: systemd-binfmt.service is missing or disabled != " 1>&2 and again > +qemu_generate_debian() { > + cat > "$EXPORTDIR/qemu-$cpu" < +package qemu-$cpu Again, !EOF is an unusual delimiter. > +qemu_set_binfmts() { > + # probe cpu type > + host_family=3D$(qemu_get_family) > + > + # register the interpreter for each cpu except for the native one > + > + for cpu in ${qemu_target_list} ; do > + magic=3D$(eval echo \$${cpu}_magic) > + mask=3D$(eval echo \$${cpu}_mask) > + family=3D$(eval echo \$${cpu}_family) Use of eval is risky; fortunately, it looks like $qemu_target_list is under your control and can't be overridden by the user's environment to do something malicious. > + > + if [ "$magic" =3D "" -o "$mask" =3D "" -o "$family" =3D "" ] ;= then "[ ... -o ... ]" is not portable. Use "[ ... ] || [ ... ]" instead. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --nXXNWnXGOO8d4qSgCtiBpPMdN7NgqcxEV Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWqpYtAAoJEKeha0olJ0NqsxUH/1IwT39feVlVR0ucDzfWcU9O mAIa75AmpQpWmBm3A1A7tMlP8AYmj6IXe06OaPm+AGOha2kI3UKdYI+g812tlWfp PzOJrRe3e3/GR1mcbFope0G6NG6SfK8+qshh9NdYbSRSopzS2CdUa69MRdl5OgjW 2DPd1lRoVGMk8NnqpFpcGl+8bfC1yeMbEgI0XdsbGcYPEAeZ5q07ihxwLMnjws5V 5DZbZQ5k5MvlbGRryA21LivI4hy9OvSWVzlD2QbRXHH5ReFKRsItRJaXXgeuxfOO tX/xQiGCX/cEjF01ucN0zPAAHvF+nJIpXfWEnodv2fttZrCQInLQNdmRN5jylHo= =IqjU -----END PGP SIGNATURE----- --nXXNWnXGOO8d4qSgCtiBpPMdN7NgqcxEV--