Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8229901ybn; Tue, 1 Oct 2019 05:18:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwK42PfDOsbWqgQSY+vdu6TuJKIW8bZgxN5M1OwIK9z5VFvOeFSz4s+/imuVxrS8uL5OGFO X-Received: by 2002:aa7:cf11:: with SMTP id a17mr25156038edy.153.1569932325506; Tue, 01 Oct 2019 05:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569932325; cv=none; d=google.com; s=arc-20160816; b=Y/TM72Z8i+aIBw/B0zojZDwJy/PYz6kZtfwBuAxKezUhf1yFNh1kMjLyOvrgVrQRVE 3d3vNTXgcyLoX4vLohWEJ+yBy4FcS92lywp5nm4aDhFS5RsoGxOOOq50saEaFIOgS1P5 pfJKwhc4ebqAGlj/J7NzmMsyDt+HzVYjqxgm3IIa43wghOJAD9Y0cHwUxKKHbLli+Ovc jRfI1NuNgMnnNYnJ5j9zD6jXHIKFaP/0zmCFM7cBRMD6Vt8ttMrVuD8SW6AaAnsDngTm rzGdXt06tx/cFbdKo1qGmsFOf6isBSMnBkjG2VbSyiBmUDLiHL9hxmWyzgGYSdbs7wnH bkwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=9hkjCrWAmYl8Hzn0M9NoT02tNI9xvkz9T7RGu9HJXvc=; b=AwHJN9ZvSP3Acyj895bnTzfGN2Z90rWvJIycMbfpLDqEU9QrTFMkOBM6aSssItrCa+ qDprGmb889xJ3xLsw7x3dV/NKqlx9yryLmh5Lel1bRYa2vOLRWj6fhZiP4SofVJqJx5c 1RqUs8JfaVkTn0hmZS1rCgD8k3rBzcaUBF9EyLkZo0/bFeJZt8SHjxQoslhlYCCGqOmz VuZIpVCHgJlMZsp0NG/FVmUPBr1ENNj/JivaGSa6BslJ6prnQI4p2amIEbuoij9S13by n9ggfs9hCJVZ2nY697+kJt9b0lEM0SNbatv9zO6VFFlf4Eu60yTmV673PCngsJIfhapF l3Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Zf3xvtMO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y64si9282187edy.434.2019.10.01.05.18.20; Tue, 01 Oct 2019 05:18:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Zf3xvtMO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733270AbfJAMRz (ORCPT + 99 others); Tue, 1 Oct 2019 08:17:55 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:24482 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfJAMRy (ORCPT ); Tue, 1 Oct 2019 08:17:54 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x91CHO42014561; Tue, 1 Oct 2019 21:17:25 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x91CHO42014561 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1569932245; bh=9hkjCrWAmYl8Hzn0M9NoT02tNI9xvkz9T7RGu9HJXvc=; h=From:To:Cc:Subject:Date:From; b=Zf3xvtMOcFMOqPb9lalb7aEUjRdygqtb2++Le+8tL3Kaq7nkVQOusOBJ8NVu0EqsT 2n7pO1I8k6auJdH+vPDQU4XrIB9MQuHXzzTk4HaenQmd5bnWZEw4gacZKl8863tMe/ r8tRagTROlRnbNCW3J/HmHF5Er3DLB9ylWlqs6IY9u79cRbKVQH4IN7loOS3Qo161t cl+1+x35XjFPETe1cNvOJBTE0JL2YaR5VyozetocY3RKG+TogOCNNXPUjx7XSbn9oz CgT16ihKjVklfdonOR2Hh0qMsTEUOsvvnalMZkn36aCDDAEoyJzXRoNQM2DwuGo6Ck mIPcyxCuc8U5Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kernel@vger.kernel.org Cc: Geert Uytterhoeven , Masahiro Yamada Subject: [PATCH] scripts/setlocalversion: clear local varaible to make it work for sh Date: Tue, 1 Oct 2019 21:17:24 +0900 Message-Id: <20191001121724.23886-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Geert Uytterhoeven reports a strange side-effect of commit 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension"), which inserts the contents of a localversion file in the build directory twice. [Steps to Reproduce] $ echo bar > localversion $ mkdir build $ cd build/ $ echo foo > localversion $ make -s -f ../Makefile defconfig include/config/kernel.release $ cat include/config/kernel.release 5.4.0-rc1foofoobar This comes down to the behavior change of 'local' variables. The 'man sh' on my Ubuntu machine, where sh is an alias to dash, explains as follows: When a variable is made local, it inherits the initial value and exported and readonly flags from the variable with the same name in the surrounding scope, if there is one. Otherwise, the variable is initially unset. [Test Code] foo () { local res echo "res: $res" } res=1 foo [Result] $ sh test.sh res: 1 $ bash test.sh res: So, scripts/setlocalversion correctly works only for bash in spite of its hashbang being #!/bin/sh. Nobody had noticed it before because CONFIG_SHELL was previously set to sh only when bash is missing, which is very unlikely to happen. The benefit of commit 858805b336be is to make people write portable and correct code. I gave it the Fixes tag since it uncovered the issue for most of people. Clear the variable 'res' in collect_files() to make it work for sh (and it also works on distributions where sh is an alias to bash). Fixes: commit 858805b336be ("kbuild: add $(BASH) to run scripts with bash-extension") Reported-by: Geert Uytterhoeven Signed-off-by: Masahiro Yamada --- scripts/setlocalversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 365b3c2b8f43..220dae0db3f1 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -126,7 +126,7 @@ scm_version() collect_files() { - local file res + local file res= for file; do case "$file" in -- 2.17.1