Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8305016ybn; Tue, 1 Oct 2019 06:21:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIoJgnlrWMcpe3bYy6aB2Ijj6bj4veRdXj9HC2VPhMemtGUnLXr0ELT8Eqqu4cw67B3EKy X-Received: by 2002:a5d:67cc:: with SMTP id n12mr18190233wrw.359.1569936113118; Tue, 01 Oct 2019 06:21:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569936113; cv=none; d=google.com; s=arc-20160816; b=YG9ekPbxx7pQo6zeNRwgiDj7JWdrg34D1fjVm8quR0Jq2ibvVvzal7npqCWxfWbijK rZKQkozDUa2YjQdMAkIL3EugKFFlDBkYMGu1YfCgs6q4dPiBe7h6+VennBxzuuwQ1BjB Bzxk+MrD5U9zmuuFn3aZJZq/2GZXTz/RTfmUmfDt5rzIsrB8vYNWt4ndQPER02cskBsc +yd2MdFMkrGzVewgku0vSuf5U5HxPBxplLNHoRyURZyiTeLsBBaL3GWtIuAyP0yVLrjx yXqj+hAjiA0Flc69UPt63HQVqBnGyfTIOzane3fddBHjHJif1h28PBRCJLZO7SQILhGf rurg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=fZmRbEsruWyw6QjQdADmS+Xo1vkXkRcFYI1pBoUt5gs=; b=YpN4xAUnrrtGbv/6iw96V5bHrO1hqLiG/AjoWOqtXMhHRTQkvl/B1dUqFkiNKOOeCV 2KXcrAp/SVG6mXMwPeJLGcB2tf+yjPsz9r0ubFuwhK/kvaaLl3RJc6gIIsCcO51qwr0Q jhN+WNj2epiMC31bRerXIupakzekci1UOSIv0ejJ8NYQAL9u9+EZpL1Z7LR/A/xTeMFU bPo7wWel6woqcPdK4Bk35Cm6L6hWemETDSU+WSvOAwzTnMlqSS1kUDFJsTDlZhQFb6ZO EQ8owERKDNlTfyb131ttX4w0/9wQT/ga8vSomSfB9opjFJLwj/JFkU30po2xQn6B+6DC XKyw== ARC-Authentication-Results: i=1; mx.google.com; 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 x19si8451046eje.336.2019.10.01.06.21.28; Tue, 01 Oct 2019 06:21:53 -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; 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 S2388314AbfJANUk (ORCPT + 99 others); Tue, 1 Oct 2019 09:20:40 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:46180 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388146AbfJANUk (ORCPT ); Tue, 1 Oct 2019 09:20:40 -0400 Received: by mail-ot1-f66.google.com with SMTP id 89so5951336oth.13 for ; Tue, 01 Oct 2019 06:20:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fZmRbEsruWyw6QjQdADmS+Xo1vkXkRcFYI1pBoUt5gs=; b=rTZBWrqmUV/5UAc9jTUKMQljp88Hb8Rp9W+C9iS3ye3tej9IoznaoVGOqWaRxOEt9o HpA4bbMkY3OIANtOX/+5zwD6kk9ySdcVkggSSDW37IGqGowgpqrMqiCZP29DnXHy28st gJQaNRyb2eGAok+KRorJ9qXCmWTnx4+Mhyp1XZa4F9Pm++KeNKFffvqMdYrMF0lpkC4C DdJpeFzsdc1uHQZdQpeS+/FuFLauxaLOwFC+jRd+MTkbFQKYc1ter14j8UQUPjOa+x69 IPFnRrNme5x72GRecm71pR06X6eL6vQPhlA554JprNhfzZ+n/rdNrYnVBuDWjTg5oZ9s nBxg== X-Gm-Message-State: APjAAAXxixnJGnhpMhFb1DaIt0C4SdVeZH5H9x3e4PFxegqYtPZDPDQf 2edie08CKYKE8vhwhmxx407aODHO2er+8e8aGUo= X-Received: by 2002:a9d:404d:: with SMTP id o13mr18265756oti.39.1569936039027; Tue, 01 Oct 2019 06:20:39 -0700 (PDT) MIME-Version: 1.0 References: <20191001121724.23886-1-yamada.masahiro@socionext.com> In-Reply-To: <20191001121724.23886-1-yamada.masahiro@socionext.com> From: Geert Uytterhoeven Date: Tue, 1 Oct 2019 15:20:27 +0200 Message-ID: Subject: Re: [PATCH] scripts/setlocalversion: clear local varaible to make it work for sh To: Masahiro Yamada Cc: Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yamada-san, s/varaible/variable/ in subject. On Tue, Oct 1, 2019 at 2:17 PM Masahiro Yamada wrote: > 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 Can you please use Reported-by: Geert Uytterhoeven instead? > Signed-off-by: Masahiro Yamada Thanks, that fixes the issue for me! Tested-by: Geert Uytterhoeven Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds