bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#29266: gzip-1.8.41 test results: help-version on HP-UX


From: Bruno Haible
Subject: bug#29266: gzip-1.8.41 test results: help-version on HP-UX
Date: Sun, 12 Nov 2017 23:47:54 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-98-generic; KDE/5.18.0; x86_64; ; )

Hi Jim,

> >> But on your system, it exits with status 2.
> >
> > Yes:
> >
> > $ ./gunzip --help > /dev/full
> > echo: No space left on device
> > $ echo $?
> > 2
> 
> Ohh...
> So it's the HP-UX shell's "echo" that is detecting the write failure
> but setting errno to 2 rather than the 1

'bash' on the same system behaves the same way:
  $ bash gunzip --help > /dev/full
  echo: No space left on device
  $ echo $?
  2

And that is despite of

  $ bash -c 'type echo'
  echo is a shell builtin

$ bash -c 'echo foo > /dev/full'
bash: line 0: echo: write error: No space left on device
$ echo $?
1
$ bash -c '/usr/bin/echo foo > /dev/full'
/usr/bin/echo: No space left on device
$ echo $?
2

It looks like the 'gunzip' script is never using the bash built-in
but always the 'echo' in $PATH. Probably because of 'exec echo ...'.

This patch:

*** gunzip.orig Sat Nov 11 20:05:54 2017
--- gunzip      Sun Nov 12 22:38:15 2017
***************
*** 50,57 ****
  Report bugs to <address@hidden>."
  
  case $1 in
! --help)    exec echo "$usage";;
! --version) exec echo "$version";;
  esac
  
  exec gzip -d "$@"
--- 50,57 ----
  Report bugs to <address@hidden>."
  
  case $1 in
! --help)    echo "$usage" || exit 1; exit 0;;
! --version) echo "$version" || exit 1; exit 0;;
  esac
  
  exec gzip -d "$@"

works fine with bash but not with /bin/sh:

$ bash gunzip --help > /dev/full
gunzip: line 53: echo: write error: No space left on device
$ echo $?
1
$ ./gunzip --help > /dev/full
$ echo $?
0

But this one works with both:

*** gunzip.orig Sat Nov 11 20:05:54 2017
--- gunzip      Sun Nov 12 22:46:39 2017
***************
*** 50,57 ****
  Report bugs to <address@hidden>."
  
  case $1 in
! --help)    exec echo "$usage";;
! --version) exec echo "$version";;
  esac
  
  exec gzip -d "$@"
--- 50,62 ----
  Report bugs to <address@hidden>."
  
  case $1 in
! # Produce output and exit with code 1 if there is a write error.
! # Use 'exec echo', not plain 'echo', because the 'echo' built-in in
! # HP-UX /bin/sh does not check for write errors.
! # Use '|| exit 1', because the 'echo' program on HP-UX exits with
! # code 2 in case of a write error, but we want code 1.
! --help)    (exec echo "$usage") || exit 1; exit 0;;
! --version) (exec echo "$version") || exit 1; exit 0;;
  esac
  
  exec gzip -d "$@"


$ bash gunzip --help > /dev/full
echo: No space left on device
$ echo $?
1
$ ./gunzip --help > /dev/full
echo: No space left on device
$ echo $?
1






reply via email to

[Prev in Thread] Current Thread [Next in Thread]