On 03/25/2016 08:16 AM, Jim Meyering wrote:
I know that mktemp's -t is not portable, but the code in init.sh was supposed to work around that. Did you see some place where that work-around failed?
Ah, sorry, I misinterpreted the debugging output. I saw a 'fail=1' and thought, "Oh, the script is failing". But it was working correctly (albeit confusingly). I reverted that part of the change to tests/init.sh in gnulib and installed further changes that I hope make the test output clearer. Revised proposed patches to gzip attached.
From f37f2da4c7722853bca1de7a7cf4e1d5211d5004 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Fri, 25 Mar 2016 12:53:50 -0700 Subject: [PATCH 1/3] Port to Alpine Linux which uses Busybox * Makefile.am (check-local): Use plain diff rather than diff -c, for portability to Busybox. --- Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index e892cdc..738c63c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -111,11 +111,11 @@ FILES_TO_CHECK = $(bin_SCRIPTS) \ $(top_srcdir)/ChangeLog $(top_srcdir)/configure $(top_srcdir)/gzip.c check-local: $(FILES_TO_CHECK) $(bin_PROGRAMS) gzip.doc.gz $(AM_V_GEN)$(new_path); { test '$(srcdir)' != . \ - || zdiff -c gzip.doc.gz; } - $(AM_V_at)$(new_path); zdiff -c $(srcdir)/gzip.doc $(srcdir)/gzip.doc + || zdiff gzip.doc.gz; } + $(AM_V_at)$(new_path); zdiff $(srcdir)/gzip.doc $(srcdir)/gzip.doc $(AM_V_at)$(new_path); zdiff $(srcdir)/gzip.doc gzip.doc.gz - $(AM_V_at)$(new_path); zdiff -c - $(srcdir)/gzip.doc <gzip.doc.gz - $(AM_V_at)$(new_path); zdiff -c gzip.doc.gz gzip.doc.gz + $(AM_V_at)$(new_path); zdiff - $(srcdir)/gzip.doc <gzip.doc.gz + $(AM_V_at)$(new_path); zdiff gzip.doc.gz gzip.doc.gz $(AM_V_at)$(new_path); zgrep -iV >/dev/null $(AM_V_at)$(new_path); \ for opt in --rsyncable '' -1 -9; do \ -- 2.5.5
From 489a904f25c5f28d7559f944372f1703b91c3ca4 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Fri, 25 Mar 2016 12:54:36 -0700 Subject: [PATCH 2/3] * tests/init.sh: Sync from Gnulib. --- tests/init.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/init.sh b/tests/init.sh index ee08022..97e4e4b 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -308,13 +308,19 @@ if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \ fi } fi -elif diff_out_=`exec 2>/dev/null; diff -c "$0" "$0" < /dev/null`; then +elif + for diff_opt_ in -U3 -c '' no; do + test "$diff_opt_" = no && break + diff_out_=`exec 2>/dev/null; diff $diff_opt_ "$0" "$0" </dev/null` && break + done + test "$diff_opt_" != no +then if test -z "$diff_out_"; then - compare_ () { diff -c "$@"; } + compare_ () { diff $diff_opt_ "$@"; } else compare_ () { - if diff -c "$@" > diff.out; then + if diff $diff_opt_ "$@" > diff.out; then # No differences were found, but AIX and HP-UX 'diff' produce output # "No differences encountered" or "There are no differences between the # files.". Hide this output. @@ -466,7 +472,6 @@ setup_ () fi initial_cwd_=$PWD - fail=0 pfx_=`testdir_prefix_` test_dir_=`mktempd_ "$initial_cwd_" "$pfx_-$ME_.XXXX"` \ @@ -550,8 +555,9 @@ mktempd_ () # Disallow any trailing slash on specified destdir: # it would subvert the post-mktemp "case"-based destdir test. case $destdir_ in - /) ;; + / | //) destdir_slash_=$destdir;; */) fail_ "invalid destination dir: remove trailing slash(es)";; + *) destdir_slash_=$destdir_/;; esac case $template_ in @@ -561,20 +567,17 @@ mktempd_ () esac # First, try to use mktemp. - d=`unset TMPDIR; { mktemp -d -t -p "$destdir_" "$template_"; } 2>/dev/null` \ - || fail=1 + d=`unset TMPDIR; { mktemp -d -t -p "$destdir_" "$template_"; } 2>/dev/null` && # The resulting name must be in the specified directory. - case $d in "$destdir_"*);; *) fail=1;; esac + case $d in "$destdir_slash_"*) :;; *) false;; esac && # It must have created the directory. - test -d "$d" || fail=1 + test -d "$d" && # It must have 0700 permissions. Handle sticky "S" bits. - perms=`ls -dgo "$d" 2>/dev/null|tr S -` || fail=1 - case $perms in drwx------*) ;; *) fail=1;; esac - - test $fail = 0 && { + perms=`ls -dgo "$d" 2>/dev/null` && + case $perms in drwx--[-S]---*) :;; *) false;; esac && { echo "$d" return } @@ -593,7 +596,7 @@ mktempd_ () i_=1 while :; do X_=`rand_bytes_ $nx_` - candidate_dir_="$destdir_/$base_template_$X_" + candidate_dir_="$destdir_slash_$base_template_$X_" err_=`mkdir -m 0700 "$candidate_dir_" 2>&1` \ && { echo "$candidate_dir_"; return; } test $MAX_TRIES_ -le $i_ && break; -- 2.5.5
From 6929140335edf5eaf5b605aebd9d139007000645 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Fri, 25 Mar 2016 12:57:05 -0700 Subject: [PATCH 3/3] Port to NetBSD 7.0 Problem reported by Assaf Gordon in: http://bugs.gnu.org/23107#13 * gzexe.in, zdiff.in, zgrep.in: Don't rely on mktemp -t, as it has a different meaning in NetBSD. --- gzexe.in | 4 ++-- zdiff.in | 4 ++-- zgrep.in | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gzexe.in b/gzexe.in index b333993..282e385 100644 --- a/gzexe.in +++ b/gzexe.in @@ -119,7 +119,7 @@ for i do mktemp_status=$? fi if test $mktemp_status -eq 0; then - tmp=`TMPDIR=$dir mktemp -t gzexeXXXXXX` + tmp=`TMPDIR=$dir mktemp` else tmp=$dir/gzexe$$ fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || { @@ -157,7 +157,7 @@ trap 'res=$? ' 0 1 2 3 5 10 13 15 if type mktemp >/dev/null 2>&1; then - gztmpdir=`mktemp -dt` + gztmpdir=`mktemp -d` else gztmpdir=/tmp/gztmp$$; mkdir $gztmpdir fi || { (exit 127); exit 127; } diff --git a/zdiff.in b/zdiff.in index f2f5435..12de3a1 100644 --- a/zdiff.in +++ b/zdiff.in @@ -111,15 +111,15 @@ elif test $# -eq 2; then esac (exit $cmp_status) else - F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog tmp= trap ' test -n "$tmp" && rm -f "$tmp" (exit 2); exit 2 ' HUP INT PIPE TERM 0 if type mktemp >/dev/null 2>&1; then - tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2 + tmp=`mktemp` || exit 2 else + F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog set -C tmp=${TMPDIR-/tmp}/$F.$$ fi diff --git a/zgrep.in b/zgrep.in index 99ace59..7ce45ae 100644 --- a/zgrep.in +++ b/zgrep.in @@ -134,7 +134,7 @@ while test $# -ne 0; do (exit 2); exit 2 ' HUP INT PIPE TERM 0 if type mktemp >/dev/null 2>&1; then - pattmp=$(mktemp -t -- "zgrep.XXXXXX") || exit 2 + pattmp=$(mktemp) || exit 2 else set -C pattmp=${TMPDIR-/tmp}/zgrep.$$ -- 2.5.5