[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Puzzle - Temp file creation



>>>>> "L" == L  <Brian> writes:

L> Chaim Frenkel writes:
L> |If there is a race condition possible, split them up. I'm partial to
L> |mkdir "tempdir.$$". sticking hostname in there, if multiple hosts are
L> |sharing this.
L> |The pid can't be reused as long as the process is still around, so
L> |the kernel will take care of the locking.

L> Hope your scripts are never run under modperl or the like, or you never
L> want to create more than one temp file in a script. And that *every other
L> script* that could be running on the same machine is well-behaved.

Okay enlighten me. What am I missing? In what way will I get a collision?

	$base = "/tmp/foo";
	$host = hostname;
	++$count;
	$temporary = "$base.$host.$$.$count";
or
	$unique = $CGIQuery->cookie('SessionId');
	$temporary = "$base.$unique";

All of the comments assume that the 'victim' does not understand how
the code is going to be used. As if the environment is totaly random.

If I need multiple temporaries, I make sure they have different names.
If some piece of code that I have no control over will create temporary
files in the same directory as I will, then we come to some
agreement as to the nomenclature?

<chaim>
-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
chaimf@pobox.com				               +1-718-236-0183

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe