From nobody Mon Feb 2 05:54:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1768555421; cv=none; d=zohomail.com; s=zohoarc; b=PF77w3+n9jzUBUoM2v1TQwmvKoIoeyEZ9xpsNFLcWZioN5++w+0L/WN0+YVQSgYBkkhdVLkwrWK4QpUBWGIlTMdUkQm036NFS38HxEwxVb/tKfbQ7FecVWZQxouXziyVi6v/0an3fatCxdfLJQeTZNHL0dEOhitrLhSeW0mKv0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768555421; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=9HT5mqOAO1VnFyB1e8ZRn1WBnmx9mdF5pHmxmWTVl5w=; b=hVUsQNqndJLy3Cechxtrrpo3cy2xyilg/21Yv6fi+KUBL5baK7jekANGpnnCLR7qmAf6zw57pwFvdC7VlfMFcqbImz3igRziwUN7etxwRxMZGZfHOuWI7Vl7r05W5yEZQuBZQabSkNRyM4FLgJYU/I+ARNwpnyK9GoWSsdSh5hg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1768555421477833.4556295197395; Fri, 16 Jan 2026 01:23:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 94ABB41BDF; Fri, 16 Jan 2026 04:23:40 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1F0AA43DF7; Fri, 16 Jan 2026 04:22:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 5D8683F328; Fri, 16 Jan 2026 04:22:21 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B4E49419E0 for ; Fri, 16 Jan 2026 04:22:20 -0500 (EST) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-u2uU-fC9PiCnSRvHabum_Q-1; Fri, 16 Jan 2026 04:22:19 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 45F8F1956058 for ; Fri, 16 Jan 2026 09:22:18 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A35141800285 for ; Fri, 16 Jan 2026 09:22:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768555340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9HT5mqOAO1VnFyB1e8ZRn1WBnmx9mdF5pHmxmWTVl5w=; b=Kve+2X5ZpSZsdS0904X1JPI7hzOYgJIlKZeFd1cztV6dheCIKWnNpXqvCq0DAnssqoE7Jw nT2jMWLjUM2oirIfSXj/NPgkaHdea64+Exew+P4rhxiLy9936pFyr0Em49A2J1eD3jursl RV43Fi41mVsB/TmEuzVS9+a3Kx57SIM= X-MC-Unique: u2uU-fC9PiCnSRvHabum_Q-1 X-Mimecast-MFC-AGG-ID: u2uU-fC9PiCnSRvHabum_Q_1768555338 To: devel@lists.libvirt.org Subject: [PATCH 1/2] libvirt-guests.sh: Declare and assign separately to avoid masking return values Date: Fri, 16 Jan 2026 10:22:13 +0100 Message-ID: <6b0e5239e45b433f6462de6b61713253cbb9638e.1768555307.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JeJlh2U1x5BH0bsLKmSCMErxFia3WVfFJgqcN8Kspms_1768555338 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HHXL7I6BONBM735XX2VYXUNSJWFNWRWG X-Message-ID-Hash: HHXL7I6BONBM735XX2VYXUNSJWFNWRWG X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1768556007198158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik In Bash, the following code does not do what you think it does: func() { local var=3D$(false) echo $? } Here, '0' is echoed even though false is designed to exit with a non-zero code. This is because in fact the last executed command is 'local' not 'false' and thus '$?' contains zero as in "yeah, the variable is successfully declared" [1]. In our libvirt-guest shell script, there are a few places like this. Now, in next commit a syntax-check rule is introduced and to keep it simple (by avoiding multi line grep) it'll deny declaring local variables and assigning their value via a subshell regardless of subsequent '$?' check. Thus, this commit may change more than necessary, strictly speaking. But in the long run, we're on the safe side. 1: https://www.shellcheck.net/wiki/SC2155 Fixes: 08071ec0f113bb1fe8dcc263cb6bf87529e8b76b Resolves: https://gitlab.com/libvirt/libvirt/-/issues/839 Signed-off-by: Michal Privoznik --- tools/libvirt-guests.sh.in | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index f2db1282ad..f57eda66fe 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -106,7 +106,9 @@ test_connect() list_guests() { local uri=3D"$1" local persistent=3D"$2" - local list=3D"$(run_virsh_c "$uri" list --uuid $persistent)" + local list=3D + + list=3D"$(run_virsh_c "$uri" list --uuid $persistent)" =20 if [ $? -ne 0 ]; then RETVAL=3D1 @@ -131,9 +133,10 @@ guest_name() { guest_is_on() { local uri=3D"$1" local uuid=3D"$2" - local id=3D"$(run_virsh "$uri" domid "$uuid")" + local id=3D =20 guest_running=3D"false" + id=3D"$(run_virsh "$uri" domid "$uuid")" if [ $? -ne 0 ]; then RETVAL=3D1 return 1 @@ -193,7 +196,8 @@ 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 + name=3D"$(guest_name "$uri" "$guest")" eval_gettext "Resuming guest \$name: " if guest_is_on "$uri" "$guest"; then if "$guest_running"; then @@ -226,11 +230,13 @@ 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 name=3D + local label=3D local bypass=3D local slept=3D0 =20 + name=3D"$(guest_name "$uri" "$guest")" + label=3D"$(eval_gettext "Suspending \$name: ")" test "x$BYPASS_CACHE" =3D x0 || bypass=3D"--bypass-cache" printf '%s...\n' "$label" run_virsh "$uri" managedsave $bypass "$guest" >/dev/null & @@ -241,7 +247,8 @@ suspend_guest() =20 slept=3D$(($slept + 1)) if [ $(($slept % 5)) -eq 0 ]; then - local progress=3D"$(run_virsh_c "$uri" domjobinfo "$guest" 2>/= dev/null | \ + local progress=3D + progress=3D"$(run_virsh_c "$uri" domjobinfo "$guest" 2>/dev/nu= ll | \ awk '/^Data processed:/{print $3, $4}')" if [ -n "$progress" ]; then printf '%s%s\n' "$label" "$progress" @@ -260,12 +267,13 @@ shutdown_guest() { local uri=3D"$1" local guest=3D"$2" - local name=3D"$(guest_name "$uri" "$guest")" + local name=3D local timeout=3D"$SHUTDOWN_TIMEOUT" local check_timeout=3D"false" local format=3D local slept=3D =20 + name=3D"$(guest_name "$uri" "$guest")" eval_gettext "Starting shutdown on guest: \$name" echo retval run_virsh "$uri" shutdown "$guest" >/dev/null || return @@ -312,8 +320,9 @@ shutdown_guest_async() { local uri=3D"$1" local guest=3D"$2" - local name=3D"$(guest_name "$uri" "$guest")" + local name=3D =20 + name=3D"$(guest_name "$uri" "$guest")" eval_gettext "Starting shutdown on guest: \$name" echo retval run_virsh "$uri" shutdown "$guest" > /dev/null @@ -365,7 +374,8 @@ print_guests_shutdown() *" $guest "*) continue;; esac =20 - local name=3D"$(guest_name "$uri" "$guest")" + local name=3D + name=3D"$(guest_name "$uri" "$guest")" if [ -n "$name" ]; then eval_gettext "Shutdown of guest \$name complete." echo @@ -482,7 +492,8 @@ stop() { =20 eval_gettext "Running guests on \$uri URI: " =20 - local list=3D"$(list_guests "$uri")" + local list=3D + list=3D"$(list_guests "$uri")" if [ $? -eq 0 ]; then local empty=3Dtrue for uuid in $list; do @@ -498,7 +509,8 @@ stop() { fi =20 if "$persistent_only"; then - local transient=3D"$(list_guests "$uri" "--transient")" + local transient=3D + transient=3D"$(list_guests "$uri" "--transient")" if [ $? -eq 0 ]; then local empty=3D"true" local uuid=3D --=20 2.52.0 From nobody Mon Feb 2 05:54:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1768555451; cv=none; d=zohomail.com; s=zohoarc; b=BtYJp/Uoe9PdXv4wcDaBK7mBk3T8KI8xPcsu/epigjTTNOjqP+r7fFz3p7uI6ZcehvMFXj65mH+ueBf+lc5jGQ7FGh/EOYebH5FXDjYdE1fnFAzKV7i0t4spndJfhLpD6LQdWNiUPETd0eREIvm/gThEI9lLLUYJoEdxg7GS4gw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768555451; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=RjKQwuMEAt1+CT0wDk9M4UW7ZYqEOzCHYvqPc4WXI6s=; b=YBqyheIhz5s5/qi/AmjUiUo+p6j8hCO5t1iXvicEsUrOglDzRjqzwPBb0ak+TznbGkWMrNjymdu9aSWu2Dh9mGOi29scBYYqDhXJ8o1CYjQvknYfnUpijbZfPgo+Vs9ZEpTn6B11zhnYuLo7L5qIKgmsoEVs6ej7lhzSFtmTvFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1768555451641628.5500126824563; Fri, 16 Jan 2026 01:24:11 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id AF81241B13; Fri, 16 Jan 2026 04:24:10 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id B80E643E4D; Fri, 16 Jan 2026 04:22:28 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id C3F653F328; Fri, 16 Jan 2026 04:22:22 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 42BB6419DC for ; Fri, 16 Jan 2026 04:22:22 -0500 (EST) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-yYcGVOMKMB6c697VZlVuog-1; Fri, 16 Jan 2026 04:22:20 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4DDF319560A1 for ; Fri, 16 Jan 2026 09:22:19 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB07D1800665 for ; Fri, 16 Jan 2026 09:22:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768555342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RjKQwuMEAt1+CT0wDk9M4UW7ZYqEOzCHYvqPc4WXI6s=; b=UN7R/1hTsJyF+l8Z7p/U0zqDEa/bfOh2vm0BNzfFsWcCDD6dngiDzseB9yD575p0fvBOKZ vTCD1a3jLfS8VTeFgiiGX/5JTZg60iqX5o44EdAg2T96ca1piin+O8ti4kx1iZqji6j5XB umIVQ9ZkJGnZbAVy655oQ6ZtXNZM33M= X-MC-Unique: yYcGVOMKMB6c697VZlVuog-1 X-Mimecast-MFC-AGG-ID: yYcGVOMKMB6c697VZlVuog_1768555339 To: devel@lists.libvirt.org Subject: [PATCH 2/2] syntax-check: Introduce sc_prohibit_local_with_subshell rule Date: Fri, 16 Jan 2026 10:22:14 +0100 Message-ID: <8aeb443e7309d9778ba69d471e0688b8fb8197a8.1768555307.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: SjNQWiOs35Z0LzhKuWpwg7FWeJHg-nM0P6ZITC0bHoA_1768555339 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5SWXNFFI6BPYO3FOBCDDTQQQQOQSJKCG X-Message-ID-Hash: 5SWXNFFI6BPYO3FOBCDDTQQQQOQSJKCG X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1768556016488158500 From: Michal Privoznik As mentioned in the previous commit, the following function doesn't echo '1' but '0': func() { local var=3D$(false) echo $? } It's explained here [1]. Since this kind of error is not easy to catch a new syntax-check rule is introduced. To avoid having multiline grep and match only those patterns where '$?' is examined, let's keep the rule simple and forbid all local declarations with subshell. 1: https://www.shellcheck.net/wiki/SC2155 Signed-off-by: Michal Privoznik --- build-aux/syntax-check.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index f605c9b0e3..ff44dfa2fe 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -394,6 +394,12 @@ sc_prohibit_g_autofree_const: halt=3D'=E2=80=98g_autofree=E2=80=99 discards =E2=80=98const=E2=80=99 qua= lifier from pointer target type' \ $(_sc_search_regexp) =20 +sc_prohibit_local_with_subshell: + @prohibit=3D'local [a-zA-Z]+=3D"?\$$\(.+' \ + in_vc_files=3D'\.sh(\.in)?$$' \ + halt=3D'local variable with subshell does not do what you think it does' \ + $(_sc_search_regexp) + =20 # Many of the function names below came from this filter: # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$'= \ --=20 2.52.0