# subroutine name: GetFileLock # Locks a file on flock-disabled systems like Win9x, so that no one # else can get to it while it is being accessed. # It checks for the existance of a lock file and if it finds it, it # waits until the lock file disappears, but not more than 20 sec. # After the lock file is gone, it opens the lock file up itself. # # Input: # $lock_file = filename to use as a temporary lock file # # Global variables used: # $no_flock - disable flock or not # %LOCK_HANDLES - hash of locked file handles sub GetFileLock { if ($no_flock) { my ($lock_file) = @_; my $endtime = time + 10; my $delta = 20/86400; # 20 seconds if (-e $lock_file && -M $lock_file > $delta) { unlink($lock_file); } while (-e $lock_file && time < $endtime) { sleep(1); # Wait 1 sec. } local *LOCK_FILE; $LOCK_HANDLES{$lock_file}=*LOCK_FILE; # Create lock file open(LOCK_FILE, ">$lock_file") or die("Error in subroutine GetFileLock: Can't open $lock_file. Reason: $!"); } }