gbranden pushed a commit to branch master
in repository groff.

commit b1cd3b77a48f56c319b8642234f39b21e260e0c3
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
Date:   Wed Apr 25 10:18:44 2018 -0400

    pic2graph: Refactor temp directory handling.
    
    contrib/pic2graph/pic2graph.sh: Issue a diagnostic and give up if the
    user's desired temporary directory does not exist.  Also document the
    Bashism $RANDOM and work around its absence.
    
    The work-around is crap entropy but slightly better than a null string
    (/bin/dash's $RANDOM), and at this point in the logic we're already on a
    system where the mktemp command is not installed, doesn't support the
    flags we need, or doesn't work.
    
    Signed-off-by: G. Branden Robinson <g.branden.robin...@gmail.com>
---
 ChangeLog                      |  8 ++++++++
 contrib/pic2graph/pic2graph.sh | 37 +++++++++++++++++++++++++------------
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 548a70e..29564d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2018-04-25  G. Branden Robinson <g.branden.robin...@gmail.com>
 
+       pic2graph: Refactor temp directory handling.
+
+       contrib/pic2graph/pic2graph.sh: Issue a diagnostic and give up
+       if the user's desired temporary directory does not exist.  Also
+       document the Bashism $RANDOM and work around its absence.
+
+2018-04-25  G. Branden Robinson <g.branden.robin...@gmail.com>
+
        pic2graph: Handle embedded whitespace in temp dir.
 
        contrib/pic2graph/pic2graph.sh: Quote shell variables having to
diff --git a/contrib/pic2graph/pic2graph.sh b/contrib/pic2graph/pic2graph.sh
index 97b486e..b229914 100644
--- a/contrib/pic2graph/pic2graph.sh
+++ b/contrib/pic2graph/pic2graph.sh
@@ -68,20 +68,33 @@ fi
 
 # create temporary directory
 tmp=
-for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp; do
-    test -z "$d" && continue
+for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp
+do
+    test -n "$d" && break
+done
+
+if ! test -d "$d"
+then
+    echo "$0: error: temporary directory \"$d\" does not exist or is" \
+        "not a directory" >&2
+    exit 1
+fi
 
-    tmp=`(umask 077 && mktemp -d -q "$d/pic2graph-XXXXXX") 2> /dev/null` \
-    && test -n "$tmp" && test -d "$tmp" \
-    && break
+if ! tmp=`(umask 077 && mktemp -d -q "$d/pic2graph-XXXXXX") 2> /dev/null`
+then
+    # mktemp failed--not installed or is a version that doesn't support those
+    # flags?  Fall back to older method which uses more predictable naming.
+    #
+    # $RANDOM is a Bashism.  The fallback of $PPID is not good 
pseudorandomness,
+    # but is supported by the stripped-down dash shell, for instance.
+    tmp="$d/pic2graph$$-${RANDOM:-$PPID}"
+    (umask 077 && mkdir "$tmp") 2> /dev/null
+fi
 
-    tmp="$d/pic2graph$$-$RANDOM"
-    (umask 077 && mkdir "$tmp") 2> /dev/null \
-    && break
-done;
-if test -z "$tmp"; then
-    echo "$0: cannot create temporary directory" >&2
-    { (exit 1); exit 1; }
+if ! test -d "$tmp"
+then
+    echo "$0: error: cannot create temporary directory \"$tmp\"" >&2
+    exit 1
 fi
 
 # See if the installed version of convert(1) is new enough to support the -trim

_______________________________________________
Groff-commit mailing list
Groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to