From nobody Sat May 4 18:53:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com ARC-Seal: i=1; a=rsa-sha256; t=1597832157; cv=none; d=zohomail.com; s=zohoarc; b=O1QdqmLwajUWRJXE26t7lKawOsDHIQ7DLqIgSuTnwWPLWFah9EQ5psJlXpzsTQ+/yQcuOFU7+ev1bifqQdNLRz2aVHgaqjjcw2eeFU86INUu/LTejnqSzu46eXr5usTAG4oObaCJvGnwO3QpLIY1xrXk+H/MatfjiceB349mf54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597832157; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ywAHHUCBcbdeA0h2MdJRLR2TfetvUObN4kuZWDQaZFE=; b=A2YtrlZbypVeLlCUKXeOgwnPAuSYrldDUg21ETarG7AfRhFeqzOPOXsLUrww+Q4V/Te2RP10Mi/kfkylOoC1qABwmBKQSRw0xsaRCked+T/fiR+53s3GWeXg704ml9nFz6s8MSR18ZYFSnQUy7XQ4weZsPu8XpUqD+4kACDiJ4c= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1597832157116361.8541388236114; Wed, 19 Aug 2020 03:15:57 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-YEFDg7LDPCyT2I6fCYx29Q-1; Wed, 19 Aug 2020 06:15:51 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 922EC393B9; Wed, 19 Aug 2020 10:15:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE73B27BCC; Wed, 19 Aug 2020 10:15:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C2B6C6037E; Wed, 19 Aug 2020 10:15:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07JAFXOo027239 for ; Wed, 19 Aug 2020 06:15:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0E942017F02; Wed, 19 Aug 2020 10:15:32 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB58F2022789 for ; Wed, 19 Aug 2020 10:15:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F1E718A0711 for ; Wed, 19 Aug 2020 10:15:26 +0000 (UTC) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-qlCT87QaMcy8hPiEwBcwwA-1; Wed, 19 Aug 2020 06:15:24 -0400 Received: from 2.general.paelzer.uk.vpn ([10.172.196.173] helo=Keschdeichel.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k8L7q-0003Tz-G4; Wed, 19 Aug 2020 10:15:22 +0000 X-MC-Unique: YEFDg7LDPCyT2I6fCYx29Q-1 X-MC-Unique: qlCT87QaMcy8hPiEwBcwwA-1 From: Christian Ehrhardt To: libvir-list@redhat.com Subject: [PATCH] tools: fix libvirt-guests.sh text assignments Date: Wed, 19 Aug 2020 12:15:20 +0200 Message-Id: <20200819101520.3519896-1-christian.ehrhardt@canonical.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false; X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Prathamesh Chavan , Christian Ehrhardt X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.003 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In libvirt 6.6 stopping guests with libvirt-guests.sh is broken. As soon as there is more than one guest one can see `systemctl stop libvirt-guests` faiing and in the log we see: libvirt-guests.sh[2455]: Running guests on default URI: libvirt-guests.sh[2457]: /usr/lib/libvirt/libvirt-guests.sh: 120: local: 2a49cb0f-1ff8-44b5-a61d-806b9e52dae2: bad variable name libvirt-guests.sh[2462]: no running guests. That is due do mutliple guests becoming a list of UUIDs. Without recognizing this as one single string the assignment breaks when using 'loc= al' (which was recently added in 6.3.0). This is because local is defined as local [option] [name[=3Dvalue] ... | - ] which makes the shell trying handle the further part of the string as variable names. In the error above that string isn't a valid variable name triggering the issue that is seen. To resolve that 'textify' all assignments that are strings or potentially can become such lists (even if they are not using the local qualifier). Fixes: 08071ec0 "tools: variables clean-up in libvirt-guests script" Signed-off-by: Christian Ehrhardt --- tools/libvirt-guests.sh.in | 136 ++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index 534c4d5e0f..d69df908d2 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -30,9 +30,9 @@ test ! -r "$sysconfdir"/rc.d/init.d/functions || =20 export TEXTDOMAIN=3D"@PACKAGE@" TEXTDOMAINDIR=3D"@localedir@" =20 -URIS=3Ddefault -ON_BOOT=3Dstart -ON_SHUTDOWN=3Dsuspend +URIS=3D"default" +ON_BOOT=3D"start" +ON_SHUTDOWN=3D"suspend" SHUTDOWN_TIMEOUT=3D300 PARALLEL_SHUTDOWN=3D0 START_DELAY=3D0 @@ -65,7 +65,7 @@ retval() { # If URI is "default" virsh is called without the "-c" argument # (using libvirt's default connection) run_virsh() { - local uri=3D$1 + local uri=3D"$1" shift =20 if [ "x$uri" =3D xdefault ]; then @@ -86,7 +86,7 @@ run_virsh_c() { # check if URI is reachable test_connect() { - local uri=3D$1 + local uri=3D"$1" =20 if run_virsh "$uri" connect 2>/dev/null; then return 0; @@ -103,9 +103,9 @@ test_connect() # --transient: list only transient guests # [none]: list both persistent and transient guests list_guests() { - local uri=3D$1 - local persistent=3D$2 - local list=3D$(run_virsh_c "$uri" list --uuid $persistent) + local uri=3D"$1" + local persistent=3D"$2" + local list=3D"$(run_virsh_c "$uri" list --uuid $persistent)" =20 if [ $? -ne 0 ]; then RETVAL=3D1 @@ -118,8 +118,8 @@ list_guests() { # guest_name URI UUID # return name of guest UUID on URI guest_name() { - local uri=3D$1 - local uuid=3D$2 + local uri=3D"$1" + local uuid=3D"$2" =20 run_virsh "$uri" domname "$uuid" 2>/dev/null } @@ -128,17 +128,17 @@ guest_name() { # check if guest UUID on URI is running # Result is returned by variable "guest_running" guest_is_on() { - local uri=3D$1 - local uuid=3D$2 - local id=3D$(run_virsh "$uri" domid "$uuid") + local uri=3D"$1" + local uuid=3D"$2" + local id=3D"$(run_virsh "$uri" domid "$uuid")" =20 - guest_running=3Dfalse + guest_running=3D"false" if [ $? -ne 0 ]; then RETVAL=3D1 return 1 fi =20 - [ -n "$id" ] && [ "x$id" !=3D x- ] && guest_running=3Dtrue + [ -n "$id" ] && [ "x$id" !=3D x- ] && guest_running=3D"true" return 0 } =20 @@ -151,9 +151,9 @@ started() { # start # Start or resume the guests start() { - local isfirst=3Dtrue + local isfirst=3D"true" local bypass=3D - local sync_time=3Dfalse + local sync_time=3D"false" local uri=3D local list=3D =20 @@ -167,10 +167,10 @@ start() { return 0 fi =20 - test "x$BYPASS_CACHE" =3D x0 || bypass=3D--bypass-cache - test "x$SYNC_TIME" =3D x0 || sync_time=3Dtrue + test "x$BYPASS_CACHE" =3D x0 || bypass=3D"--bypass-cache" + test "x$SYNC_TIME" =3D x0 || sync_time=3D"true" while read uri list; do - local configured=3Dfalse + local configured=3D"false" local confuri=3D local guest=3D =20 @@ -178,7 +178,7 @@ start() { for confuri in $URIS; do set +f if [ "x$confuri" =3D "x$uri" ]; then - configured=3Dtrue + configured=3D"true" break fi done @@ -192,14 +192,14 @@ start() { =20 eval_gettext "Resuming guests on \$uri URI..."; echo for guest in $list; do - local name=3D$(guest_name "$uri" "$guest") + local name=3D"$(guest_name "$uri" "$guest")" eval_gettext "Resuming guest \$name: " if guest_is_on "$uri" "$guest"; then if "$guest_running"; then gettext "already active"; echo else if "$isfirst"; then - isfirst=3Dfalse + isfirst=3D"false" else sleep $START_DELAY fi @@ -223,25 +223,25 @@ start() { # was saved. suspend_guest() { - local uri=3D$1 - local guest=3D$2 - local name=3D$(guest_name "$uri" "$guest") - local label=3D$(eval_gettext "Suspending \$name: ") + local uri=3D"$1" + local guest=3D"$2" + local name=3D"$(guest_name "$uri" "$guest")" + local label=3D"$(eval_gettext "Suspending \$name: ")" local bypass=3D local slept=3D0 =20 - test "x$BYPASS_CACHE" =3D x0 || bypass=3D--bypass-cache + test "x$BYPASS_CACHE" =3D x0 || bypass=3D"--bypass-cache" printf '%s...\n' "$label" run_virsh "$uri" managedsave $bypass "$guest" >/dev/null & - local virsh_pid=3D$! + local virsh_pid=3D"$!" while true; do sleep 1 kill -0 "$virsh_pid" >/dev/null 2>&1 || break =20 slept=3D$(($slept + 1)) if [ $(($slept % 5)) -eq 0 ]; then - local progress=3D$(run_virsh_c "$uri" domjobinfo "$guest" 2>/d= ev/null | \ - awk '/^Data processed:/{print $3, $4}') + local progress=3D"$(run_virsh_c "$uri" domjobinfo "$guest" 2>/= dev/null | \ + awk '/^Data processed:/{print $3, $4}')" if [ -n "$progress" ]; then printf '%s%s\n' "$label" "$progress" else @@ -257,11 +257,11 @@ suspend_guest() # was successfully shutdown or the timeout defined by $SHUTDOWN_TIMEOUT ex= pired. shutdown_guest() { - local uri=3D$1 - local guest=3D$2 - local name=3D$(guest_name "$uri" "$guest") - local timeout=3D$SHUTDOWN_TIMEOUT - local check_timeout=3Dfalse + local uri=3D"$1" + local guest=3D"$2" + local name=3D"$(guest_name "$uri" "$guest")" + local timeout=3D"$SHUTDOWN_TIMEOUT" + local check_timeout=3D"false" local format=3D local slept=3D =20 @@ -270,11 +270,11 @@ shutdown_guest() retval run_virsh "$uri" shutdown "$guest" >/dev/null || return =20 if [ $timeout -gt 0 ]; then - check_timeout=3Dtrue - format=3D$(eval_gettext "Waiting for guest %s to shut down, %d sec= onds left\n") + check_timeout=3D"true" + format=3D"$(eval_gettext "Waiting for guest %s to shut down, %d se= conds left\n")" else slept=3D0 - format=3D$(eval_gettext "Waiting for guest %s to shut down\n") + format=3D"$(eval_gettext "Waiting for guest %s to shut down\n")" fi while ! $check_timeout || [ "$timeout" -gt 0 ]; do sleep 1 @@ -309,9 +309,9 @@ shutdown_guest() # was issued to libvirt to allow parallel shutdown. shutdown_guest_async() { - local uri=3D$1 - local guest=3D$2 - local name=3D$(guest_name "$uri" "$guest") + local uri=3D"$1" + local guest=3D"$2" + local name=3D"$(guest_name "$uri" "$guest")" =20 eval_gettext "Starting shutdown on guest: \$name" echo @@ -332,8 +332,8 @@ guest_count() # Result is returned in "guests_shutting_down" check_guests_shutdown() { - local uri=3D$1 - local guests_to_check=3D$2 + local uri=3D"$1" + local guests_to_check=3D"$2" local guest=3D =20 guests_shutting_down=3D @@ -354,9 +354,9 @@ check_guests_shutdown() # a shutdown complete notice for guests that have finished print_guests_shutdown() { - local uri=3D$1 - local before=3D$2 - local after=3D$3 + local uri=3D"$1" + local before=3D"$2" + local after=3D"$3" local guest=3D =20 for guest in $before; do @@ -364,7 +364,7 @@ print_guests_shutdown() *" $guest "*) continue;; esac =20 - local name=3D$(guest_name "$uri" "$guest") + local name=3D"$(guest_name "$uri" "$guest")" if [ -n "$name" ]; then eval_gettext "Shutdown of guest \$name complete." echo @@ -376,28 +376,28 @@ print_guests_shutdown() # Shutdown guests GUESTS on machine URI in parallel shutdown_guests_parallel() { - local uri=3D$1 - local guests=3D$2 + local uri=3D"$1" + local guests=3D"$2" local on_shutdown=3D - local check_timeout=3Dfalse - local timeout=3D$SHUTDOWN_TIMEOUT + local check_timeout=3D"false" + local timeout=3D"$SHUTDOWN_TIMEOUT" local slept=3D local format=3D =20 if [ $timeout -gt 0 ]; then - check_timeout=3Dtrue - format=3D$(eval_gettext "Waiting for %d guests to shut down, %d se= conds left\n") + check_timeout=3D"true" + format=3D"$(eval_gettext "Waiting for %d guests to shut down, %d s= econds left\n")" else slept=3D0 - format=3D$(eval_gettext "Waiting for %d guests to shut down\n") + format=3D"$(eval_gettext "Waiting for %d guests to shut down\n")" fi while [ -n "$on_shutdown" ] || [ -n "$guests" ]; do while [ -n "$guests" ] && [ $(guest_count "$on_shutdown") -lt "$PARALLEL_SHUTDOWN" ]; = do set -- $guests - local guest=3D$1 + local guest=3D"$1" shift - guests=3D$* + guests=3D"$*" if [ -z "$(echo $on_shutdown | grep $guest)" ] && [ -n "$(guest_name "$uri" "$guest")" ]; then shutdown_guest_async "$uri" "$guest" @@ -428,7 +428,7 @@ shutdown_guests_parallel() fi fi =20 - local on_shutdown_prev=3D$on_shutdown + local on_shutdown_prev=3D"$on_shutdown" check_guests_shutdown "$uri" "$on_shutdown" on_shutdown=3D"$guests_shutting_down" print_guests_shutdown "$uri" "$on_shutdown_prev" "$on_shutdown" @@ -438,14 +438,14 @@ shutdown_guests_parallel() # stop # Shutdown or save guests on the configured uris stop() { - local suspending=3Dtrue + local suspending=3D"true" local uri=3D =20 # last stop was not followed by start [ -f "$LISTFILE" ] && return 0 =20 if [ "x$ON_SHUTDOWN" =3D xshutdown ]; then - suspending=3Dfalse + suspending=3D"false" if [ $SHUTDOWN_TIMEOUT -lt 0 ]; then gettext "SHUTDOWN_TIMEOUT must be equal or greater than 0" echo @@ -463,13 +463,13 @@ stop() { =20 eval_gettext "Running guests on \$uri URI: " =20 - local list=3D$(list_guests "$uri") + local list=3D"$(list_guests "$uri")" if [ $? -eq 0 ]; then local empty=3Dtrue for uuid in $list; do "$empty" || printf ", " printf %s "$(guest_name "$uri" "$uuid")" - empty=3Dfalse + empty=3D"false" done =20 if "$empty"; then @@ -479,15 +479,15 @@ stop() { fi =20 if "$suspending"; then - local transient=3D$(list_guests "$uri" "--transient") + local transient=3D"$(list_guests "$uri" "--transient")" if [ $? -eq 0 ]; then - local empty=3Dtrue + local empty=3D"true" local uuid=3D =20 for uuid in $transient; do if "$empty"; then eval_gettext "Not suspending transient guests on U= RI: \$uri: " - empty=3Dfalse + empty=3D"false" else printf ", " fi @@ -495,7 +495,7 @@ stop() { done echo # reload domain list to contain only persistent guests - list=3D$(list_guests "$uri" "--persistent") + list=3D"$(list_guests "$uri" "--persistent")" if [ $? -ne 0 ]; then eval_gettext "Failed to list persistent guests on \$ur= i" echo @@ -582,7 +582,7 @@ rh_status() { # usage [val] # Display usage string, then exit with VAL (defaults to 2). usage() { - local program_name=3D$0 + local program_name=3D"$0" eval_gettext "Usage: \$program_name {start|stop|status|restart|"\ "condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"; echo exit ${1-2} @@ -612,7 +612,7 @@ case "$1" in rh_status ;; shutdown) - ON_SHUTDOWN=3Dshutdown + ON_SHUTDOWN=3D"shutdown" stop ;; *) --=20 2.28.0