From nobody Mon Feb 2 05:55:25 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=1768823297; cv=none; d=zohomail.com; s=zohoarc; b=eo71NUKD/CqsahdAa2ZH1OnE2mW4GGg5YZpT9O8zVmAtRKxaKL04OZXlbDVyRvdtkM6a9lM492MlwQBUlUB4YjTsrSEvW2oXVy3FRpG/AahSvYIXpiPB+fL6Mjq0RiAjxFKmYeNrGKAGF/j8/O7L6QOut2GczR+WNhxyBdgSlgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768823297; 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=dzMtv/rP6ULWIWIcK8QmZiFc4dek7E+p7EP11MkxYj4=; b=L7LF2Lwh3wSKQCU4fJ+NeA56DnRLmILZYtrVtXRCPZNJSU2OspU+KF22M/DvJ3ytNFSfc9app6AgO5ECipkinU9TU0hU8glbna35GB4V9kyVknFA66hvwJSsUKPfjdpRSart8zSjXnXz5cl/bZNo/1mRJ734QAlCg8kY43LwVH4= 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 1768823297700687.6380980250261; Mon, 19 Jan 2026 03:48:17 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id DD6F543ED3; Mon, 19 Jan 2026 06:48:16 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id D008543F2B; Mon, 19 Jan 2026 06:46:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id C8F5841C1F; Mon, 19 Jan 2026 06:46:49 -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 467AD41BA1 for ; Mon, 19 Jan 2026 06:46:49 -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-460-WNmzsgHTM0GXThAiMw3kWw-1; Mon, 19 Jan 2026 06:46:47 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 E3E8E19560A6 for ; Mon, 19 Jan 2026 11:46:46 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D5D119560A7 for ; Mon, 19 Jan 2026 11:46:46 +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=1768823209; 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=dzMtv/rP6ULWIWIcK8QmZiFc4dek7E+p7EP11MkxYj4=; b=Jm6x03ty1ansH0DPCDvdmC1Xn8M7Hm21Bjr+fkHQ/Ijw1/4lQfVFDT5/jjUlHWa3J0boAf PPdUlIamvshxxMDoUoas3y4WHX6rhoSAl4lvuzDOschyjQ3gr8mz6nTJL0m1y+kho+9ghU ciWB6X4BUoVzF/IuWA5LkCUDIjv1SPM= X-MC-Unique: WNmzsgHTM0GXThAiMw3kWw-1 X-Mimecast-MFC-AGG-ID: WNmzsgHTM0GXThAiMw3kWw_1768823207 To: devel@lists.libvirt.org Subject: [PATCH v2 1/3] libvirt-guests.sh: Declare and assign separately to avoid masking return values Date: Mon, 19 Jan 2026 12:46:41 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: raI7YYd_W366PXKBrwF53TiJ6lrcj79DNXElxJOhKpQ_1768823207 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JBHDLRA7QVR2LB5WAPVSDTMCJHDNSFZI X-Message-ID-Hash: JBHDLRA7QVR2LB5WAPVSDTMCJHDNSFZI 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: 1768823299926158500 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. Fix them. 1: bash_builtins(1) Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/libvirt-guests.sh.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index f2db1282ad..e05bfdba61 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -106,8 +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 =20 + list=3D"$(run_virsh_c "$uri" list --uuid $persistent)" if [ $? -ne 0 ]; then RETVAL=3D1 return 1 @@ -482,7 +483,8 @@ stop() { =20 eval_gettext "Running guests on \$uri URI: " =20 - local list=3D"$(list_guests "$uri")" + local list + list=3D"$(list_guests "$uri")" if [ $? -eq 0 ]; then local empty=3Dtrue for uuid in $list; do @@ -498,7 +500,8 @@ stop() { fi =20 if "$persistent_only"; then - local transient=3D"$(list_guests "$uri" "--transient")" + local transient + 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:55:25 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=1768823335; cv=none; d=zohomail.com; s=zohoarc; b=BfKwdfmtwbQ7KbqRh0YFIu/IjyFnJvxg6ldQV7GNPi0BV8C4+ex0Dl4M04//uivdYafAeZ/gkxlCVkgI2iPDknIif36GgzRs1dvcA3cXZBRBkCx6qlnI+yNkoRrNAfSFA6PrdWbrSG9fPy7vLt78UxiEfgTMNkIvStoOCAQsncE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768823335; 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=b1TK5LcrYNFIvJH9EEI466rPQ4Igr+IRa0Y4Ybbm22c=; b=O5yJ7Fj2zLf8sikd1k88SkwTCo57KutgS2E/i++k2vBE9lg1HNPtpwEGU8rAq/P+xVyXKGmvoAM2luWwGp8GkwPcbqXAZMoTm5AESETBtJR4VCLgHzFS8FjYIisrntIpv26A6Ln0Rb9Ta6sKnGS+tHq1YpSHAlFIASpu0oaxwro= 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 1768823335503770.8774875213663; Mon, 19 Jan 2026 03:48:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8F75D43DF7; Mon, 19 Jan 2026 06:48:54 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 63EFF43F80; Mon, 19 Jan 2026 06:46:59 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8CC9741BA1; Mon, 19 Jan 2026 06:46:50 -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 1575C41C3D for ; Mon, 19 Jan 2026 06:46:50 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-7t1zhLMNNN280p0_c4vOPw-1; Mon, 19 Jan 2026 06:46:48 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B21C21800473 for ; Mon, 19 Jan 2026 11:46:47 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4B9F819560A7 for ; Mon, 19 Jan 2026 11:46:47 +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=1768823209; 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=b1TK5LcrYNFIvJH9EEI466rPQ4Igr+IRa0Y4Ybbm22c=; b=hfAYl8HMYkmu/JYdkqTIkkdS/X/fggFEgAKyhHq6ebn376ZG0GMEt8cHRQjf4TtuIq8kLR eeJ5NYpu9Lb8tui8f0EoOAU0Qztb5soGDc52whHzMqqIP5SVKEL5NLYDbYER3ags7bqXDE 1iqud4IXgA/Gt97xLRfG0EBSt1KWUSY= X-MC-Unique: 7t1zhLMNNN280p0_c4vOPw-1 X-Mimecast-MFC-AGG-ID: 7t1zhLMNNN280p0_c4vOPw_1768823207 To: devel@lists.libvirt.org Subject: [PATCH v2 2/3] libvirt-guest.sh.in: Fix logical error in guest_is_on() Date: Mon, 19 Jan 2026 12:46:42 +0100 Message-ID: <12f285573136ee69644fe10fa4bebe8d709a2997.1768823107.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: b9w1G1tp5lkoSldr1q6jhg0m81-r43C0SjmZrWHYj70_1768823207 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GWIYMBP4XJX7JYHCXJ3XADTA7DT2R7BS X-Message-ID-Hash: GWIYMBP4XJX7JYHCXJ3XADTA7DT2R7BS 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: 1768823336130158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The guest_is_on() function is documented to check whether given domain is running and set guest_running variable accordingly. It does so by running virsh (transitively), then setting the variable and only after that comparing $? variable. This is obviously wrong, because after the guest_running variable assignment the $? variable no longer holds the exit code of virsh. Even worse, as explained in the previous commit, it never held that value in the first place. Fix this by firstly setting the global variable and only after that running virsh. Fixes: 08071ec0f113bb1fe8dcc263cb6bf87529e8b76b Resolves: https://gitlab.com/libvirt/libvirt/-/issues/839 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/libvirt-guests.sh.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index e05bfdba61..66a39b9178 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -132,9 +132,10 @@ guest_name() { guest_is_on() { local uri=3D"$1" local uuid=3D"$2" - local id=3D"$(run_virsh "$uri" domid "$uuid")" + local id =20 guest_running=3D"false" + id=3D"$(run_virsh "$uri" domid "$uuid")" if [ $? -ne 0 ]; then RETVAL=3D1 return 1 --=20 2.52.0 From nobody Mon Feb 2 05:55:25 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=1768823369; cv=none; d=zohomail.com; s=zohoarc; b=SyRySuGQwoqLwBvp9Facnu/VCJhKzpHzG5NcvYD8N9t7KGEv6KIIJVL4RPeBgA/dbPZZd5gLB+15eaKGUoY0B96eN/jXtj2x2UD1eUGp9M70ZfO2bwnNVq8c5q0CqU775U7P81kxIQ6TYqvrADInHPqr9cdxTPLkLFem0pWJLP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768823369; 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=VpT+N0//GXWE1JpsFoDhQ6SZD/g4DuDADsvYwvRbqAs=; b=TMNXzUKTYuvKLG02i00r+B25L/WHxha9+mZiNrAL/SEu7cPMzYwjOcGieqQ0dhwuyxBGJlPlpZaHetfWxPfEzhdy2yL9raWtzDlh3Nut8TPr3nFgpMj68+EF8fzajXLIajAwf4WeQMc5Nh3rUMTJDPV/KOk15Rq4YSkMw/JayNw= 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 1768823369425471.968217343075; Mon, 19 Jan 2026 03:49:29 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 9819041C49; Mon, 19 Jan 2026 06:49:28 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 431E043FE1; Mon, 19 Jan 2026 06:47:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 6CB0B41BA1; Mon, 19 Jan 2026 06:46:51 -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)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E64CA41C1F for ; Mon, 19 Jan 2026 06:46:50 -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-564-3bhCA4IKMuq1I07dxROz_w-1; Mon, 19 Jan 2026 06:46:49 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 B159B19560A6 for ; Mon, 19 Jan 2026 11:46:48 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 19DB219560A7 for ; Mon, 19 Jan 2026 11:46:47 +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=1768823210; 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=VpT+N0//GXWE1JpsFoDhQ6SZD/g4DuDADsvYwvRbqAs=; b=KnQNLY4cVLZ6eS59RmA66pOp+EogktlgQgyNwVw9f5NW5faiuuK7g1BruAbMdaDv8RExyG W5dzHqm1cA2TXY3YDbONjWqgKsOo52pIMUs2WD7sjzN3ETC8+Ir6N6ObgcsoGMNyvib449 gXE2C2zpgG2ptIjG4rv4QV3dUt4Dg1k= X-MC-Unique: 3bhCA4IKMuq1I07dxROz_w-1 X-Mimecast-MFC-AGG-ID: 3bhCA4IKMuq1I07dxROz_w_1768823208 To: devel@lists.libvirt.org Subject: [PATCH v2 3/3] syntax-check: Introduce sc_prohibit_local_with_subshell rule Date: Mon, 19 Jan 2026 12:46:43 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: izsFvSPsVoLLHZLjLV7gNdamUyrFFNZBcuDjtx8SwLw_1768823208 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IO452LHRNNWDTW4RTCM5SZLX6GHI4ZYG X-Message-ID-Hash: IO452LHRNNWDTW4RTCM5SZLX6GHI4ZYG 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: 1768823372244158500 From: Michal Privoznik In shell, the following function doesn't echo '1' but '0': func() { local var=3D$(false) echo $? } This is because '$?' does not refer to 'false' but 'local'. The bash_builtins(1) manpage explains it well. And it also mentions other commands behaving the same: export, declare and readonly. Since it is really easy to miss this pattern, introduce a syntax-check rule. Mind you, the following patter (which passes the rule) does check for the subshell exit code: func() { local var var=3D$(false) echo $? } Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- build-aux/syntax-check.mk | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index f605c9b0e3..022e8e6550 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -394,6 +394,17 @@ 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: + @err=3D0; for f in $$($(VC_LIST_EXCEPT) | $(GREP) -E '\.sh(\.in)?$$'); do= \ + lines=3D$$( $(AWK) \ + '/^\s*(local|export|declare|readonly)\s+.*=3D/ { nr=3DNR; c=3D1; next }= \ + /^\s*$$/ { if (c) next } \ + /\$$\?/ { if (c) { print nr; c=3D0; } next } \ + { c=3D0 }' $$f ) ; \ + for l in $$lines; do echo $$f:$$l 1>&2; err=3D1; done ; \ + done; \ + test $$err -eq 0 || { msg=3D"Declare and assign separately to avoid maski= ng return values" $(_sc_say_and_exit) } + =20 # Many of the function names below came from this filter: # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$'= \ --=20 2.52.0