diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-03-06 00:17:41 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-03-06 00:18:30 -0800 |
commit | 61cd88ef7492a180e2d91d110db116e8a8f7c049 (patch) | |
tree | 5266ba83d4f71e8bd70d939720f5f90dc56c9d70 /zgrep.in | |
parent | 3471e27de87bb81abd6aa67f4391d3fce9a35437 (diff) | |
download | gzip-61cd88ef7492a180e2d91d110db116e8a8f7c049.tar.gz |
gzip: port zgrep to Solaris 11.2
Problem reported by Assaf Gordon in: http://bugs.gnu.org/22900#11
* zgrep.in: Port to Solaris 11.2 /bin/sh (ksh 93u 2011-02-08),
where $? is 256+SIG when a process was killed with signal SIG, and
where 'exit 257' is equivalent to 'exit 1'. Apparently some other
sh implementations use 256+128+SIG. So, instead of using plain
'exit $?', use the equivalent of 'exit ((128 * (128 <= $?)) + $? %
128)' within the script, and use the equivalent of 'kill -$($? %
128)' at the top level if the exit status is 128 or more.
Diffstat (limited to 'zgrep.in')
-rw-r--r-- | zgrep.in | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -183,6 +183,7 @@ do if test $r -eq 1; then printf '%s\n' "$i" || r=2 fi + test 256 -le $r && r=$(expr 128 + $r % 128) exit $r } elif test $with_filename -eq 0 && @@ -202,12 +203,13 @@ do sed_script="s|^|$i:|" # Fail if grep or sed fails. - r=$( - exec 4>&1 - (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&- - ) && exit $r - r=$? - test 1 -lt $r && exit $r || exit 2 + if r=$( + exec 4>&1 + (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&- + ) || { r=$?; test $r -lt 2 && r=2; :; }; then + test 256 -le $r && r=$(expr 128 + $r % 128) + exit $r + fi fi >&3 5>&- ) r=$? @@ -220,14 +222,16 @@ do # Use the more serious of the grep and gzip statuses. test $r -lt $gzip_status && r=$gzip_status - # Exit immediately on software configuration error. - test 126 -le $r && exit $r - # Accumulate the greatest status, except consider 0 to be greater than 1. if test $r -le 1 && test $res -le 1; then test $r -lt $res else test $res -lt $r fi && res=$r + + # Exit immediately on a serious error. + test 126 -le $res && break done + +test 128 -le $res && kill -$(expr $res % 128) $$ exit $res |