linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KERNEL BUILD: Make the setlocalversion script POSIX-compliant.
@ 2010-07-18  8:26 Michał Górny
  2010-07-20 14:00 ` Michal Marek
  0 siblings, 1 reply; 3+ messages in thread
From: Michał Górny @ 2010-07-18  8:26 UTC (permalink / raw)
  To: Michal Marek; +Cc: linux-kernel, trivial

The 'source' builtin is a bash alias to the '.' (dot) builtin. While the
former is supported only by bash, the latter is specified in POSIX and
works fine with all POSIX-compliant shells I am aware of.

The '$_' special parameter is specific to bash. It is partially
supported in dash too but it always evaluates to the current script path
(which causes the script to enter a loop recursively re-executing
itself). This is why I have replaced the two occurences of '$_' with the
explicit parameter.

The 'local' builtin is another example of bash-specific code. Although
it is supported by all POSIX-compliant shells I am aware of, it is not
part of POSIX specification and thus the code should not rely on it
assigning a specific value to the local variable. Moreover, the 'posh'
shell has a limited version of 'local' builtin not supporting direct
variable assignments. Thus, I have broken one of the 'local'
declarations down into a (non-POSIX) 'local' declaration and a plain
(POSIX-compliant) variable assignment.

Signed-off-by: Michał Górny <gentoo@mgorny.alt.pl>
---

There is one 'bashism' left which I wasn't able to fix -- the use of
'test -ef'. I'm not aware of any POSIX equivalent of that.

 scripts/setlocalversion |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index d6a866e..a7b9f76 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -30,11 +30,12 @@ fi
 
 scm_version()
 {
-	local short=false
+	local short
+	short=false
 
 	cd "$srctree"
 	if test -e .scmversion; then
-		cat "$_"
+		cat .scmversion
 		return
 	fi
 	if test "$1" = "--short"; then
@@ -136,7 +137,7 @@ if $scm_only; then
 fi
 
 if test -e include/config/auto.conf; then
-	source "$_"
+	. include/config/auto.conf
 else
 	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
 	exit 1
-- 
1.7.1.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KERNEL BUILD: Make the setlocalversion script POSIX-compliant.
  2010-07-18  8:26 [PATCH] KERNEL BUILD: Make the setlocalversion script POSIX-compliant Michał Górny
@ 2010-07-20 14:00 ` Michal Marek
  2010-07-20 21:16   ` Michał Górny
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Marek @ 2010-07-20 14:00 UTC (permalink / raw)
  To: Michał Górny; +Cc: linux-kernel, trivial

On 18.7.2010 10:26, Michał Górny wrote:
> The 'source' builtin is a bash alias to the '.' (dot) builtin. While the
> former is supported only by bash, the latter is specified in POSIX and
> works fine with all POSIX-compliant shells I am aware of.
> 
> The '$_' special parameter is specific to bash. It is partially
> supported in dash too but it always evaluates to the current script path
> (which causes the script to enter a loop recursively re-executing
> itself). This is why I have replaced the two occurences of '$_' with the
> explicit parameter.
> 
> The 'local' builtin is another example of bash-specific code. Although
> it is supported by all POSIX-compliant shells I am aware of, it is not
> part of POSIX specification and thus the code should not rely on it
> assigning a specific value to the local variable. Moreover, the 'posh'
> shell has a limited version of 'local' builtin not supporting direct
> variable assignments. Thus, I have broken one of the 'local'
> declarations down into a (non-POSIX) 'local' declaration and a plain
> (POSIX-compliant) variable assignment.
> 
> Signed-off-by: Michał Górny <gentoo@mgorny.alt.pl>

Thanks a lot, applied to the kbuild tree.


> ---
> 
> There is one 'bashism' left which I wasn't able to fix -- the use of
> 'test -ef'. I'm not aware of any POSIX equivalent of that.

Me neither, POSIX does not know stat(1) AFAICS. Does it matter in real
life? Is there a distro that installs posh or a similarly strict shell
as /bin/sh? It seems to work with dash after your changes.

Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KERNEL BUILD: Make the setlocalversion script POSIX-compliant.
  2010-07-20 14:00 ` Michal Marek
@ 2010-07-20 21:16   ` Michał Górny
  0 siblings, 0 replies; 3+ messages in thread
From: Michał Górny @ 2010-07-20 21:16 UTC (permalink / raw)
  To: Michal Marek; +Cc: linux-kernel, trivial

On Tue, 20 Jul 2010 16:00:29 +0200
Michal Marek <mmarek@suse.cz> wrote:

> > There is one 'bashism' left which I wasn't able to fix -- the use of
> > 'test -ef'. I'm not aware of any POSIX equivalent of that.
> 
> Me neither, POSIX does not know stat(1) AFAICS. Does it matter in real
> life? Is there a distro that installs posh or a similarly strict shell
> as /bin/sh? It seems to work with dash after your changes.

I am not aware of any, and it does work with dash indeed. That's why I
have submitted the patch. I left that notice mostly because the actual
description suggested the script becomes 'POSIX-compliant'.

The second reason for that notice is that someone might want to fix
that sometime. But I guess the best way would be through complete
change of the check logic.

-- 
Best regards,
Michał Górny

<http://mgorny.alt.pl>
<xmpp:mgorny@jabber.ru>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-20 21:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-18  8:26 [PATCH] KERNEL BUILD: Make the setlocalversion script POSIX-compliant Michał Górny
2010-07-20 14:00 ` Michal Marek
2010-07-20 21:16   ` Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).