From nobody Mon Feb 2 07:29:39 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 --- 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