[8220] in bugtraq

home help back first fref pref prev next nref lref last post

Re: /tmp race in mc-4.5.0

daemon@ATHENA.MIT.EDU (Bennett Todd)
Thu Oct 15 14:06:13 1998

Date: 	Wed, 14 Oct 1998 16:51:58 -0400
Reply-To: Bennett Todd <bet@MORDOR.NET>
From: Bennett Todd <bet@MORDOR.NET>
X-To:         Pavel Machek <pavel@BUG.UCW.CZ>
To: BUGTRAQ@NETSPACE.ORG
In-Reply-To:  <19981013004104.21353@bug.ucw.cz>; from Pavel Machek on Tue,
              Oct 13, 1998 at 12:41:04AM +0200

1998-10-13-00:41:04 Pavel Machek:
> [...] until someone invents safe & portable way of how to work
> with temporary files from shell.
>
> (Actually, is this safe? It might be safe & portable, unfortunately,
> it is also slow & ugly)
>
>     TMPDIR=/tmp/mctmpdir.$$
>     mkdir $TMPDIR || exit 0
>     cd $TMPDIR
>     do_something > $TMPDIR/file
>     rm $TMPDIR/file
>     rmdir $TMPDIR

If I were doing something like this, I'd probably code

        progname=`basename $0`
        die(){ echo "$progname: $*">&2; exit 1; }
        umask 077
        tmp=/tmp/$progname.$$
        trap "rm -rf $tmp" 0
        mkdir $tmp || die "can't mkdir $tmp"

        # use $tmp/whatever, $tmp/whateverelse for tmp files

-Bennett

home help back first fref pref prev next nref lref last post