Unportable use of uname in pg_upgrade test script

Started by Tom Laneover 13 years ago6 messages
#1Tom Lane
tgl@sss.pgh.pa.us

BTW, I tried the pg_upgrade regression tests this morning on my dinosaur
HPUX box, and it promptly fell over with:

uname: illegal option -- o
usage: uname [-amnrsvil] [-S nodename]
make: *** [check] Error 1

This is not terribly surprising, because the -o option is nowhere to be
seen in the Single Unix Spec definition of uname; which means this is
likely to fail on other platforms too. I would suggest using -s, or no
option at all, or finding some other way to identify Windows/MSys.

regards, tom lane

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#1)
Re: Unportable use of uname in pg_upgrade test script

On 09/29/2012 12:13 PM, Tom Lane wrote:

BTW, I tried the pg_upgrade regression tests this morning on my dinosaur
HPUX box, and it promptly fell over with:

uname: illegal option -- o
usage: uname [-amnrsvil] [-S nodename]
make: *** [check] Error 1

This is not terribly surprising, because the -o option is nowhere to be
seen in the Single Unix Spec definition of uname; which means this is
likely to fail on other platforms too. I would suggest using -s, or no
option at all, or finding some other way to identify Windows/MSys.

The trouble with uname -s is that its output is a bit variable. I think
this will work:

testhost=`uname -a | sed 's/.* //'`

cheers

andrew

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#2)
Re: Unportable use of uname in pg_upgrade test script

Andrew Dunstan <andrew@dunslane.net> writes:

The trouble with uname -s is that its output is a bit variable. I think
this will work:

testhost=`uname -a | sed 's/.* //'`

What do you mean by "a bit variable"? And why would that fix it? The
output of -a is *defined* to be the same as -s followed by other stuff.
The reference page I'm looking at also points out that the -s string
can contain embedded blanks.

regards, tom lane

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#3)
Re: Unportable use of uname in pg_upgrade test script

On 09/29/2012 01:06 PM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

The trouble with uname -s is that its output is a bit variable. I think
this will work:
testhost=`uname -a | sed 's/.* //'`

What do you mean by "a bit variable"?

On one of my machines uname -s return MINGW32_NT5.1

On another it says MINGW32_NT6.1

And why would that fix it? The
output of -a is *defined* to be the same as -s followed by other stuff.
The reference page I'm looking at also points out that the -s string
can contain embedded blanks.

Exactly, the sed script pulls the last token from the line, which is
Msys on all my Mingw systems.

If you want to do it another way we could possibly pass the PORTNAME
from the global make file.

cheers

andrew

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#4)
Re: Unportable use of uname in pg_upgrade test script

Andrew Dunstan <andrew@dunslane.net> writes:

Exactly, the sed script pulls the last token from the line, which is
Msys on all my Mingw systems.

Perhaps that's "uname -v"?

If you want to do it another way we could possibly pass the PORTNAME
from the global make file.

That might be safer. The last few words of uname's output are
*completely* unstandardized (the spec says that implementation-defined
fields can be added to -a's output ...)

regards, tom lane

Show quoted text

cheers

andrew

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Andrew Dunstan (#4)
Re: Unportable use of uname in pg_upgrade test script

On Sat, 2012-09-29 at 13:33 -0400, Andrew Dunstan wrote:

On 09/29/2012 01:06 PM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

The trouble with uname -s is that its output is a bit variable. I think
this will work:
testhost=`uname -a | sed 's/.* //'`

What do you mean by "a bit variable"?

On one of my machines uname -s return MINGW32_NT5.1

On another it says MINGW32_NT6.1

You could do

case $testhost in
MINGW*) something;;

Or call config.guess, which exists more or less for this purpose.