|< 1 2 >| | 13 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
jons+2007-12-15 15:09:35--Schon klar, aber dafür existiert die Funktion http://perldoc.perl.org/functions/flock.html, das ganze drumherum ist eigentlich nicht nötig.so wie ich es gelesen habe, macht dieser Lockmechanismus schon Sinn um betreffende Datendateien vor einer Schädigung zu schützen.
unlink("$require_path/$file_handle/$lock_file") or die "Löschen von ($require_path/$file_handle/$lock_file) schlug fehl: $!";
1
2
3
4
Sun Dec 23 11:42:48 2007|submit_new_ad_details|LOCK|Standard Timeout
Sun Dec 23 11:45:45 2007|ad_maintenance|LOCK|Standard Timeout
Sun Dec 23 11:45:54 2007|ad_maintenance|LOCK|Standard Timeout
Sun Dec 23 11:49:12 2007|submit_new_ad_details|LOCK|Standard Timeout
|< 1 2 >| | 13 Einträge, 2 Seiten |