line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Shared::Var::Common; |
6
|
|
|
|
|
|
|
|
7
|
63
|
|
|
63
|
|
816
|
use v5.12.5; |
|
63
|
|
|
|
|
256
|
|
8
|
63
|
|
|
63
|
|
589
|
use warnings; |
|
63
|
|
|
|
|
118
|
|
|
63
|
|
|
|
|
2354
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
63
|
|
|
63
|
|
349
|
use base qw/Exporter/; |
|
63
|
|
|
|
|
139
|
|
|
63
|
|
|
|
|
7201
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw/__lock __store __retrieve/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
63
|
|
|
63
|
|
452
|
use Fcntl qw(:DEFAULT :flock); |
|
63
|
|
|
|
|
180
|
|
|
63
|
|
|
|
|
32638
|
|
17
|
63
|
|
|
63
|
|
5655
|
use Storable; |
|
63
|
|
|
|
|
180101
|
|
|
63
|
|
|
|
|
3922
|
|
18
|
63
|
|
|
63
|
|
491
|
use File::Spec; |
|
63
|
|
|
|
|
154
|
|
|
63
|
|
|
|
|
2957
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# $PARENT_PID gets set when Rex starts. This value remains the same after the |
21
|
|
|
|
|
|
|
# process forks. So $PARENT_PID is always the pid of the parent process. $$ |
22
|
|
|
|
|
|
|
# however is always the pid of the current process. |
23
|
|
|
|
|
|
|
our $PARENT_PID = $$; |
24
|
|
|
|
|
|
|
our $FILE = File::Spec->catfile( File::Spec->tmpdir(), "vars.db.$PARENT_PID" ); |
25
|
|
|
|
|
|
|
our $LOCK_FILE = |
26
|
|
|
|
|
|
|
File::Spec->catfile( File::Spec->tmpdir(), "vars.db.lock.$PARENT_PID" ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub __lock { |
29
|
1120
|
50
|
|
1120
|
|
59908
|
sysopen( my $dblock, $LOCK_FILE, O_RDONLY | O_CREAT ) or die($!); |
30
|
1120
|
50
|
|
|
|
28040
|
flock( $dblock, LOCK_EX ) or die($!); |
31
|
|
|
|
|
|
|
|
32
|
1120
|
|
|
|
|
5479
|
my $ret = $_[0]->(); |
33
|
|
|
|
|
|
|
|
34
|
1120
|
|
|
|
|
56292
|
close($dblock); |
35
|
|
|
|
|
|
|
|
36
|
1120
|
|
|
|
|
13441
|
return $ret; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub __store { |
40
|
292
|
|
|
292
|
|
673
|
my $ref = shift; |
41
|
292
|
|
|
|
|
1434
|
store( $ref, $FILE ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub __retrieve { |
45
|
1120
|
100
|
|
1120
|
|
15222
|
return {} unless -f $FILE; |
46
|
1102
|
|
|
|
|
7042
|
return retrieve($FILE); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub END { |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# return if we exiting a child process |
53
|
63
|
100
|
|
63
|
|
46172
|
return unless $$ eq $PARENT_PID; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# we are exiting the master process |
56
|
28
|
100
|
|
|
|
2838
|
unlink $FILE if -f $FILE; |
57
|
28
|
100
|
|
|
|
2348
|
unlink $LOCK_FILE if -f $LOCK_FILE; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |