From 500aac04d41967c2771b08d765d5c64c64a0e775 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 11 Jun 2024 15:09:55 -0700 Subject: [PATCH] mktempd: use GNU-style -t if available MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This better satisfies Jim Meyering’s point in: https://lists.gnu.org/archive/html/bug-gnulib/2016-03/msg00074.html that it’s more useful when each temporary test directory name includes the corresponding test’s name. * build-aux/mktempd: Try mktemp -t only with GNU syntax, so that NetBSD mktemp fails. Also, reject templates beginning with "-" so that they are not treated as options. * tests/init.sh (mktempd_): Likewise. --- ChangeLog | 12 ++++++++++++ build-aux/mktempd | 7 +++++-- tests/init.sh | 8 ++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4104be72a9..d870fdb148 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2024-06-11 Paul Eggert + + mktempd: use GNU-style -t if available + This better satisfies Jim Meyering’s point in: + https://lists.gnu.org/archive/html/bug-gnulib/2016-03/msg00074.html + that it’s more useful when each temporary test directory name + includes the corresponding test’s name. + * build-aux/mktempd: Try mktemp -t only with GNU syntax, so that + NetBSD mktemp fails. Also, reject templates beginning with "-" so + that they are not treated as options. + * tests/init.sh (mktempd_): Likewise. + 2024-06-11 Collin Funk mktempd: Invoke mktemp portably. diff --git a/build-aux/mktempd b/build-aux/mktempd index 542a4016fe..cc4824a3eb 100755 --- a/build-aux/mktempd +++ b/build-aux/mktempd @@ -84,14 +84,17 @@ mktempd() esac case $template in + -*) die "invalid template: $template (cannot start with '-')";; *XXXX) ;; *) die "invalid template: $template (must have a suffix of at least 4 X's)";; esac fail=0 - # First, try to use mktemp. - d=`env -u TMPDIR mktemp -d -p "$destdir" "$template" 2>/dev/null` \ + # First, try GNU mktemp, where -t has no option-argument. + # Put -t last, as GNU mktemp allows, so that the incompatible NetBSD mktemp + # (where -t has an option-argument) fails instead of creating a junk dir. + d=`env -u TMPDIR mktemp -d -p "$destdir" "$template" -t 2>/dev/null` \ || fail=1 # The resulting name must be in the specified directory. diff --git a/tests/init.sh b/tests/init.sh index 4689b6b758..6effae27c7 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -338,13 +338,17 @@ mktempd_ () esac case $template_ in + -*) fail _ \ + "invalid template: $template_ (must not begin with '-')";; *XXXX) ;; *) fail_ \ "invalid template: $template_ (must have a suffix of at least 4 X's)";; esac - # First, try to use mktemp. - d=`unset TMPDIR; { mktemp -d -p "$destdir_" "$template_"; } 2>/dev/null` && + # First, try GNU mktemp, where -t has no option-argument. + # Put -t last, as GNU mktemp allows, so that the incompatible NetBSD mktemp + # (where -t has an option-argument) fails instead of creating a junk dir. + d=`unset TMPDIR; { mktemp -d -p "$destdir_" "$template_" -t; } 2>/dev/null` && # The resulting name must be in the specified directory. case $d in "$destdir_slash_"*) :;; *) false;; esac && -- 2.39.5