[PATCH] V2 mktemp: fix -u option if TMPDIR is set

Ron Yorston rmy at tigress.co.uk
Fri Sep 21 15:08:50 UTC 2012


Ron Yorston <rmy at tigress.co.uk> wrote:
>Tito <farmatito at tiscali.it> wrote:
>>Seems to work like debian's mktemp with my patch applied,
>>maybe needs more testing......
>>
>>debian:~$ cd Desktop/busybox
>>debian:~/Desktop/busybox$ mktemp -t -p /var/tmp -u temp.XXXXXX
>>/var/tmp/temp.D0pKak
>>debian:~/Desktop/busybox$ export TMPDIR=/tmp
>>debian:~/Desktop/busybox$ mktemp -t -p /var/tmp -u temp.XXXXXX
>>/tmp/temp.irsv2d
>>debian:~/Desktop/busybox$
>
>Indeed, I'd just worked that out.  And that is the documented behaviour
>of coreutils mktemp.
>
>That being the case Tito's patch is correct.

Actually, I've changed my mind.  When TMPDIR is set and tempnam is
being called as tempnam("./", "temp.") it returns a filename like
"/tmp/temp.W8U6w5".  It guarantees that this file does not exist.
Tito's patch strips off the directory path and returns "temp.W8U6w5",
which comes with no such guarantee.

There's also the problem that tempnam only uses the first five characters
of the template.  So a valid command like

   mktemp -u tmpdir/temp.XXXXXX

results in output like "tmpdivTbGrF".  This is guaranteed not to exist,
but it's in the wrong place.

Anyway, after wasting far too much time trying to get tempnam to do
what I want I've now decided that using mktemp(3) is the easiest
solution.  Despite the dire warnings in the man page.  And that the
template has to have six Xs.

Patch to follow.

Ron


More information about the busybox mailing list