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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
*** ./sendmail-8.13.4/contrib/qtool.pl Wed Mar 5 16:11:54 2003
--- ./sendmail-8.13.4/contrib/qtool.pl Wed Mar 5 15:59:10 2003
***************
*** 355,373 ****
sub lock_file
{
my $file_name = shift;
my $result;
$result = sysopen(FILE_TO_LOCK, $file_name, Fcntl::O_RDWR);
if (!$result)
{
return (undef, "Unable to open '$file_name': $!");
}
! $result = flock(FILE_TO_LOCK, Fcntl::LOCK_EX | Fcntl::LOCK_NB);
! if (!$result)
{
return (undef, "Could not obtain lock on '$file_name': $!");
}
return (\*FILE_TO_LOCK, undef);
}
--- 355,394 ----
sub lock_file
{
my $file_name = shift;
my $result;
+ my $FLOCK_STRUCT;
+ my $fcntllock;
+
+ # Supposedly under linux
+ # my $FLOCK_STRUCT = 's s l l i';
+ # But I think perl's using __off64_t instead of __off_t
+ # my $FLOCK_STRUCT = 's s l l l l i';
+ # Screw it, its all zero anyway...
+
+ $FLOCK_STRUCT = 's H60';
+ $fcntllock = pack($FLOCK_STRUCT, F_WRLCK,
+ "000000000000000000000000000000000000000000000000000000000000");
+
$result = sysopen(FILE_TO_LOCK, $file_name, Fcntl::O_RDWR);
if (!$result)
{
+ # print "Unable to open '$file_name': $!";
return (undef, "Unable to open '$file_name': $!");
}
! $result = fcntl (FILE_TO_LOCK, F_SETLK, $fcntllock);
!
! # print "Fcntl Lock result on $file_name = $result\n";
!
! # $result = flock(FILE_TO_LOCK, Fcntl::LOCK_EX | Fcntl::LOCK_NB);
! # print "Lock result on $file_name = $result\n";
! # if (!$result)
! if ($result ne "0 but true")
{
+ # print "Could not obtain lock on '$file_name': $!\n";
return (undef, "Could not obtain lock on '$file_name': $!");
}
return (\*FILE_TO_LOCK, undef);
}
***************
*** 387,399 ****
sub unlock_file
{
my $file = shift;
my $result;
! $result = flock($file, Fcntl::LOCK_UN);
! if (!$result)
{
return "Unlock failed on '$result': $!";
}
return undef;
--- 408,428 ----
sub unlock_file
{
my $file = shift;
my $result;
+ my $FLOCK_STRUCT;
+ my $fcntllock;
! $FLOCK_STRUCT = 's H60';
! $fcntllock = pack($FLOCK_STRUCT, F_UNLCK,
! "000000000000000000000000000000000000000000000000000000000000");
! $result = fcntl (FILE_TO_LOCK, F_SETLK, $fcntllock);
!
! if ($result ne "0 but true")
! # $result = flock($file, Fcntl::LOCK_UN);
! # if (!$result)
{
return "Unlock failed on '$result': $!";
}
return undef;
|