Subject: misc/23447: mktemp(1) manual improvent
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <aniou@smutek.pl>
List: netbsd-bugs
Date: 11/15/2003 11:34:22
>Number:         23447
>Category:       misc
>Synopsis:       mktemp(1) manual  improvent
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 15 11:35:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Piotr Meyer
>Release:        -current
>Organization:
>Environment:
NetBSD czyzyk.smutek.pl 1.6ZE NetBSD 1.6ZE (CZYZYK) #1: Tue Nov 11 12:16:22 CET 2003  root@czyzyk.smutek.pl:/mnt/nfs/NetBSD-current/src/sys/arch/i386/compile/CZYZYK i386
>Description:
Programs from "EXAMPLES" section not working if invoked with full path.
It may be problem (small, but still problem) for newbies:

------
EXAMPLES
     The following sh(1) fragment illustrates a simple use of mktemp where the
     script should quit if it cannot get a safe temporary file.

           TMPFILE=`mktemp /tmp/$0.XXXXXX` || exit 1
           echo "program output" >> $TMPFILE

     To allow the use of $TMPDIR:

           TMPFILE=`mktemp -t $0` || exit 1
           echo "program output" >> $TMPFILE

     In this case, we want the script to catch the error itself.

           TMPFILE=`mktemp -q /tmp/$0.XXXXXX`
           if [ $? -ne 0 ]; then
                   echo "$0: Can't create temp file, exiting..."
                   exit 1
           fi
-----
>How-To-Repeat:
Create small, sample program (copy from manual), named test1.sh,
in (for example) /tmp dir:

TMPFILE=`mktemp -q /tmp/$0.XXXXXX`
if [ $? -ne 0 ]; then
  echo "$0: Can't create temp file, exiting..."
  exit 1
fi

then run it: '/tmp/test1.sh' - program will fail - cannot make tempfile.
Then try 'cd /tmp; ./test1.sh' - will working fine. 
>Fix:
Make small changes (like in old Debian 2.2):


First sample:

p=`basename $0`
TMPFILE=`mktemp /tmp/$p.XXXXXX` || exit 1
echo "program output" >> $TMPFILE


Second sample:

p=`basename $0`
TMPFILE=`mktemp -t $p` || exit 1
echo "program output" >> $TMPFILE


Third sample:

p=`basename $0`
TMPFILE=`mktemp -q /tmp/$p.XXXXXX`
if [ $? -ne 0 ]; then
   echo "$p: Can't create temp file, exiting..."
   exit 1
fi


>Release-Note:
>Audit-Trail:
>Unformatted: