sub exclusive_lockfile { # check to see if we got an exclusive lock on the file # and if not, sleep 1 second and try again until we have # tried for a total of 20 seconds. If we could not get # an exclusive lock within 20 seconds, let's exit with an # error message. my ($file_handle) = @_; $lock_file = "$file_handle.lock"; $sleep_count = 0; $request = "$as{'request'}"; if (-M "$require_path/$file_handle/$lock_file" > .001) { unlink("$require_path/$file_handle/$lock_file"); rmdir("$require_path/$file_handle"); &log_flock($file_handle, "Forced Unlock Performed", $request); } # perform a check for a lock that may have gotten left behind # because an error occurred previously. while ($sleep_count < 20) { if (!-e "$require_path/$file_handle") { mkdir("$require_path/$file_handle", 0777); chmod(0777, "$require_path/$file_handle"); open(LOCK_FILE, ">$require_path/$file_handle/$lock_file"); flock(LOCK_FILE, 2) if ($flock == 1); last; } else { $sleep_count++; if ($sleep_count > 19) { &log_flock($file_handle, "Standard Timeout", $request); &error_cannot_lock; } sleep(1); next; } } # end of while } # end of sub