From mark@ukug.uk.freebsd.org  Thu Jun  1 12:21:15 2000
Return-Path: <mark@ukug.uk.freebsd.org>
Received: from mta02-svc.server.ntlworld.com (mta02-svc.ntlworld.com [62.253.162.42])
	by hub.freebsd.org (Postfix) with ESMTP id 22FD337B9D8
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  1 Jun 2000 12:21:14 -0700 (PDT)
	(envelope-from mark@ukug.uk.freebsd.org)
Received: from parish.my.domain ([62.253.86.40])
          by mta02-svc.server.ntlworld.com
          (InterMail vM.4.01.02.27 201-229-119-110) with ESMTP
          id <20000601202047.QDHQ10065.mta02-svc.server.ntlworld.com@parish.my.domain>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Thu, 1 Jun 2000 20:20:47 +0000
Received: (from mark@localhost)
	by parish.my.domain (8.9.3/8.9.3) id UAA00790
	for FreeBSD-gnats-submit@freebsd.org; Thu, 1 Jun 2000 20:20:58 +0100 (BST)
	(envelope-from mark)
Message-Id: <20000601202058.D232@parish>
Date: Thu, 01 Jun 2000 16:04:55 +0100
From: Mark Ovens <mark@ukug.uk.freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] Code example in mktemp(1) doesn't work
X-Send-Pr-Version: 3.2

>Number:         18953
>Category:       docs
>Synopsis:       [PATCH] Code example in mktemp(1) doesn't work
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    asmodai
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 01 12:30:01 PDT 2000
>Closed-Date:    Sun Jun 4 02:11:34 PDT 2000
>Last-Modified:  Sun Jun 04 02:11:50 PDT 2000
>Originator:     Mark Ovens
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
>Environment:

	4.0-STABLE

>Description:

	The example code uses ``$0'' in the generation of the filename.
	This fails because sh(1) returns a fully qualified pathname
	for ``$0'' in a script.

>How-To-Repeat:

	# cat > /usr/local/bin/foobar
	#!/bin/sh

	TMPFILE=`mktemp /tmp/$0.XXXXXX` || exit 1
	echo "program output" >> $TMPFILE
	^D
	# chmod 777 /usr/local/bin/foobar
	# rehash
	# foobar
	mktemp: mkstemp failed on /tmp//usr/local/bin/foobar.Za3487: No such file or directory
	#

>Fix:


*** /usr/share/man/man1/mktemp.1.orig	Sat May  6 19:55:50 2000
--- /usr/share/man/man1/mktemp.1	Sun May 28 15:24:20 2000
***************
*** 152,170 ****
  where the script should quit if it cannot get a safe
  temporary file.
  .Bd -literal -offset indent
! TMPFILE=`mktemp /tmp/$0.XXXXXX` || exit 1
  echo "program output" >> $TMPFILE
  .Ed
  .Pp
  To allow the use of $TMPDIR:
  .Bd -literal -offset indent
! TMPFILE=`mktemp -t $0` || exit 1
  echo "program output" >> $TMPFILE
  .Ed
  .Pp
  In this case, we want the script to catch the error itself.
  .Bd -literal -offset indent
! TMPFILE=`mktemp -q /tmp/$0.XXXXXX`
  if [ $? -ne 0 ]; then
  	echo "$0: Can't create temp file, exiting..."
  	exit 1
--- 152,173 ----
  where the script should quit if it cannot get a safe
  temporary file.
  .Bd -literal -offset indent
! tempfoo=`basename $0`
! TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1
  echo "program output" >> $TMPFILE
  .Ed
  .Pp
  To allow the use of $TMPDIR:
  .Bd -literal -offset indent
! tempfoo=`basename $0`
! TMPFILE=`mktemp -t ${tempfoo}` || exit 1
  echo "program output" >> $TMPFILE
  .Ed
  .Pp
  In this case, we want the script to catch the error itself.
  .Bd -literal -offset indent
! tempfoo=`basename $0`
! TMPFILE=`mktemp -q /tmp/${tempfoo}.XXXXXX`
  if [ $? -ne 0 ]; then
  	echo "$0: Can't create temp file, exiting..."
  	exit 1


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->asmodai 
Responsible-Changed-By: asmodai 
Responsible-Changed-When: Sun Jun 4 02:04:35 PDT 2000 
Responsible-Changed-Why:  
Botched PR. 

I'll commit this in a sec. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18953 
State-Changed-From-To: open->closed 
State-Changed-By: asmodai 
State-Changed-When: Sun Jun 4 02:11:34 PDT 2000 
State-Changed-Why:  
Committed. 

Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18953 
>Unformatted:
