in reply to Avoiding race conditions
As for the filenames. Is the 'user' actually logged in (via some way you have an equiv of REMOTE_USER)? I have used things like $ENV{REMOTE_USER}.$$.file.ext for simple anti-race names. I also use the following to generate a random name:
my @set = ('a' .. 'z', 'A' .. 'Z'); my $length = 8; # Change length if desired my $random = join "" => map {$set [rand @set]} 1 .. $length; my $tmp_file = $random . "." . $$ . ".ext";
Many people have their own way to get a unique name. I tend to like adding a login name (if available), the PID (assuming I will unlink() the file when done), and some random string. If you are extra paranoid (or extra careful :) you could also add a sempahore file with the name of your temp file, and lock it. If you can't get a lock on it, then the name must be in use and you can generate another.
Cheers,
KM
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Avoiding race conditions
by swiftone (Curate) on Apr 24, 2001 at 21:03 UTC | |
by KM (Priest) on Apr 24, 2001 at 21:22 UTC | |
by swiftone (Curate) on Apr 24, 2001 at 22:38 UTC |