[MINC-development] patches for tmpnam

Steve ROBBINS minc-development@bic.mni.mcgill.ca
Thu, 13 Mar 2003 10:35:56 -0500


On Tue, Mar 11, 2003 at 09:03:55PM -0500, Peter NEELIN wrote:
> On Mon, 10 Mar 2003, Steve ROBBINS wrote:
> 
> > On Mon, Mar 10, 2003 at 10:34:19AM -0500, Robert VINCENT wrote:
> > >
> > > I thought that having the function create the file avoids the worst
> > > aspects of the race condition, since the file is known to have been
> > > created successfully with relatively secure permissions and ownership.
> >
> > No, that buys you nothing.  Once you close the file, all bets are
> > off.
> 
> I'm not sure that this is correct. mkstemp creates the file and returns a
> file descriptor. The file is NOT unlinked, so closing it leaves it in
> place with the correct ownership and permissions.

You're right.  I was somehow thinking that the file got unlinked after
opening, but as you say, that is only true of tmpfile().

So for systems that have mkstemp(), there is no race.  Excellent!

[If mkstemp() is not available, the race remains, but this is no
worse than it was previously.]

-S