From nobody Fri May 17 05:00:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168994027850914.42373831404791; Fri, 21 Jul 2023 04:51:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qMoex-0002Kd-PV; Fri, 21 Jul 2023 07:51:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMoeq-0002IH-Fu for qemu-devel@nongnu.org; Fri, 21 Jul 2023 07:50:53 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMoem-0001LK-Ez for qemu-devel@nongnu.org; Fri, 21 Jul 2023 07:50:51 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 3812B15742; Fri, 21 Jul 2023 14:50:37 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 56E6418861; Fri, 21 Jul 2023 14:50:32 +0300 (MSK) Received: (nullmailer pid 3224662 invoked by uid 1000); Fri, 21 Jul 2023 11:50:32 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: Laurent Vivier , Michael Tokarev Subject: [PATCH] scripts/qemu-binfmt-conf.sh: refresh Date: Fri, 21 Jul 2023 14:50:31 +0300 Message-Id: <20230721115031.3224648-1-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1689940283291100002 Content-Type: text/plain; charset="utf-8" Currently qemu-binfmt-conf.sh does a number of strange things. 1. --systemd requires an argument - the CPU type to register, while --debian (which is actually --binfmt-support) does not accept such an argument, so it is not possible to specify which CPU(s) to register for debian. 2. Why this "ALL" at all? 3. it just ignores extra command-line arguments. It would be logical to specify which CPUs to register (multiple!) as the additional arguments. 4. Even if a CPU is explicitly requested, it does not register anything if this CPU is of the same family as host one. But this is wrong, since quite often it *is* desirable to do this registration, - like, when running in i386 when the system is not capable of running x86-64 binaries, and countless other examples 5. It ignores errors 6. It ignores wrong command line arguments Fix this, and simplify things a bit. 1. Stop accepting an argument for --systemd. With getopt_long, this argument, if given, will be returned as a non-optional parameter so compatibility with current version is preserved. 2. Accept optional arguments and generate registration for the given CPUs only. In case no extra arguments are given, register for all supportd CPUs except of the same family as host. 3. Recognze "ALL" "CPU" to keep compatibility with current version (but do not document it). 4. Warn but perform registration anyway if a cpu of the same family has been requested. 5. In help text, use --debian and --systemd as alternatives to each other, to make it clear the two can not be used at the same time. 6. Tiny optimization of eval expression. 7. Fold the list of supported CPUs to fit in 80 columns. 8. Exit with non-zero code in case registration fails or the command line is wrong. 9. Remove explicit checking for writability of various things. Signed-off-by: Michael Tokarev --- scripts/qemu-binfmt-conf.sh | 89 +++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index 6ef9f118d9..27d506000d 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -182,10 +182,10 @@ qemu_get_family() { =20 usage() { cat <&2 - exit 1 - fi +echo $qemu_target_list | fold -w68 -s | sed 's/^/ /' } =20 qemu_check_bintfmt_misc() { @@ -246,8 +242,6 @@ qemu_check_bintfmt_misc() { exit 1 fi fi - - qemu_check_access /proc/sys/fs/binfmt_misc/register } =20 installed_dpkg() { @@ -260,14 +254,12 @@ qemu_check_debian() { elif ! installed_dpkg binfmt-support ; then echo "WARNING: package binfmt-support is needed" 1>&2 fi - qemu_check_access "$EXPORTDIR" } =20 qemu_check_systemd() { if ! systemctl -q is-enabled systemd-binfmt.service ; then echo "WARNING: systemd-binfmt.service is missing or disabled" 1>&2 fi - qemu_check_access "$EXPORTDIR" } =20 qemu_generate_register() { @@ -287,16 +279,16 @@ qemu_generate_register() { =20 qemu_register_interpreter() { echo "Setting $qemu as binfmt interpreter for $cpu" - qemu_generate_register > /proc/sys/fs/binfmt_misc/register + qemu_generate_register > /proc/sys/fs/binfmt_misc/register || exit 1 } =20 qemu_generate_systemd() { echo "Setting $qemu as binfmt interpreter for $cpu for systemd-binfmt.= service" - qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" + qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" || exit 1 } =20 qemu_generate_debian() { - cat > "$EXPORTDIR/qemu-$cpu" < "$EXPORTDIR/qemu-$cpu" <&2 - continue + echo "ERROR: unknown cpu $cpu" >&2 + exit 1 fi =20 qemu=3D"$QEMU_PATH/qemu-$cpu" @@ -329,9 +327,12 @@ qemu_set_binfmts() { fi =20 qemu=3D"$qemu$QEMU_SUFFIX" - if [ "$host_family" !=3D "$family" ] ; then - $BINFMT_SET + if [ "$host_family" =3D "$family" ] ; then + [ -n "$explicit" ] || continue + echo "WARNING: requested CPU $cpu is of the same family as hos= t CPU" >&2 + echo "WARNING: this might break the system" >&2 fi + $BINFMT_SET done } =20 @@ -347,9 +348,9 @@ PERSISTENT=3Dno PRESERVE_ARG0=3Dno QEMU_SUFFIX=3D"" =20 -_longopts=3D"debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,crede= ntial:,\ +_longopts=3D"debian,systemd,qemu-path:,qemu-suffix:,exportdir:,help,creden= tial:,\ persistent:,preserve-argv0:" -options=3D$(getopt -o ds:Q:S:e:hc:p:g:F: -l ${_longopts} -- "$@") +options=3D$(getopt -o dsQ:S:e:hc:p:g:F: -l ${_longopts} -- "$@") || exit 1 eval set -- "$options" =20 while true ; do @@ -363,23 +364,6 @@ while true ; do CHECK=3Dqemu_check_systemd BINFMT_SET=3Dqemu_generate_systemd EXPORTDIR=3D${EXPORTDIR:-$SYSTEMDDIR} - shift - # check given cpu is in the supported CPU list - if [ "$1" !=3D "ALL" ] ; then - for cpu in ${qemu_target_list} ; do - if [ "$cpu" =3D "$1" ] ; then - break - fi - done - - if [ "$cpu" =3D "$1" ] ; then - qemu_target_list=3D"$1" - else - echo "ERROR: unknown CPU \"$1\"" 1>&2 - usage - exit 1 - fi - fi ;; -Q|--qemu-path) shift @@ -409,12 +393,19 @@ while true ; do shift PRESERVE_ARG0=3D"$1" ;; - *) + --) + shift break ;; + *) + exit 1 + ;; esac shift done =20 $CHECK -qemu_set_binfmts +if [ ALL =3D "$1" ]; then + set -- +fi +qemu_set_binfmts "$@" --=20 2.39.2