line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cluster::Init::Conf; |
2
|
5
|
|
|
5
|
|
47828
|
use strict; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
195
|
|
3
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
187
|
|
4
|
5
|
|
|
5
|
|
5226
|
use Data::Dump qw(dump); |
|
5
|
|
|
|
|
50143
|
|
|
5
|
|
|
|
|
451
|
|
5
|
5
|
|
|
5
|
|
5587
|
use Time::HiRes qw(time); |
|
5
|
|
|
|
|
10821
|
|
|
5
|
|
|
|
|
26
|
|
6
|
5
|
|
|
5
|
|
6415
|
use Carp::Assert; |
|
5
|
|
|
|
|
6966
|
|
|
5
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
# use Cluster::Init::DB; |
8
|
5
|
|
|
5
|
|
3930
|
use Cluster::Init::Util qw(debug); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# use Cluster::Init::Daemon; |
10
|
|
|
|
|
|
|
# use base qw(Cluster::Init::Util); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
my $class = shift; |
16
|
|
|
|
|
|
|
my $self = {@_}; |
17
|
|
|
|
|
|
|
bless $self, $class; |
18
|
|
|
|
|
|
|
affirm { $self->{cltab} }; |
19
|
|
|
|
|
|
|
affirm { $self->{context} }; |
20
|
|
|
|
|
|
|
$self->{'socket'}||="/var/run/clinit/clinit.s"; |
21
|
|
|
|
|
|
|
$self->{'clstat'}||="/var/run/clinit/clstat"; |
22
|
|
|
|
|
|
|
$self->{'log'}||="/var/run/clinit/log"; |
23
|
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# read cltab process entries by line number |
27
|
|
|
|
|
|
|
sub line |
28
|
|
|
|
|
|
|
{ |
29
|
|
|
|
|
|
|
my $self=shift; |
30
|
|
|
|
|
|
|
my $line=shift; |
31
|
|
|
|
|
|
|
$self->read_cltab; |
32
|
|
|
|
|
|
|
my $raw=${$self->{raw}}[$line]; |
33
|
|
|
|
|
|
|
my $proc = Cluster::Init::Process->new(%$raw); |
34
|
|
|
|
|
|
|
return $proc; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# read first cltab process entry |
38
|
|
|
|
|
|
|
sub firstline |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
my $self=shift; |
41
|
|
|
|
|
|
|
$self->read_cltab; |
42
|
|
|
|
|
|
|
my @raw = @{$self->{raw}}; |
43
|
|
|
|
|
|
|
for (my $i=1; $i < @raw; $i++) |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my $raw=$raw[$i]; |
46
|
|
|
|
|
|
|
next unless $raw; |
47
|
|
|
|
|
|
|
my $proc = Cluster::Init::Process->new(%$raw); |
48
|
|
|
|
|
|
|
$self->{prevline}=$i; |
49
|
|
|
|
|
|
|
return $proc; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
return undef; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# read next cltab process entry |
55
|
|
|
|
|
|
|
sub nextline |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
my $self=shift; |
58
|
|
|
|
|
|
|
my $line=$self->{prevline} || 1; |
59
|
|
|
|
|
|
|
$self->read_cltab; |
60
|
|
|
|
|
|
|
my @raw = @{$self->{raw}}; |
61
|
|
|
|
|
|
|
for (my $i=$line; $i < @raw; $i++) |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
my $raw=$raw[$i]; |
64
|
|
|
|
|
|
|
next unless $raw; |
65
|
|
|
|
|
|
|
my $proc = Cluster::Init::Process->new(%$raw); |
66
|
|
|
|
|
|
|
$self->{prevline}=$i; |
67
|
|
|
|
|
|
|
return $proc; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# return highest line number in cltab |
74
|
|
|
|
|
|
|
sub max |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
my $self=shift; |
77
|
|
|
|
|
|
|
$self->read_cltab; |
78
|
|
|
|
|
|
|
my @raw = @{$self->{raw}}; |
79
|
|
|
|
|
|
|
return @raw - 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# does not set prevline |
83
|
|
|
|
|
|
|
# read cltab process entry by tag name |
84
|
|
|
|
|
|
|
sub tag |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
my $self=shift; |
87
|
|
|
|
|
|
|
my $tag=shift; |
88
|
|
|
|
|
|
|
$self->read_cltab; |
89
|
|
|
|
|
|
|
my @raw = @{$self->{raw}}; |
90
|
|
|
|
|
|
|
my $raw; |
91
|
|
|
|
|
|
|
for $raw (@raw) |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
next unless $raw; |
94
|
|
|
|
|
|
|
next unless $raw->{tag} eq $tag; |
95
|
|
|
|
|
|
|
my $proc = Cluster::Init::Process->new(%$raw); |
96
|
|
|
|
|
|
|
return $proc; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
return undef; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# does not set prevline |
102
|
|
|
|
|
|
|
# read cltab process entries by group name |
103
|
|
|
|
|
|
|
sub group |
104
|
|
|
|
|
|
|
{ |
105
|
|
|
|
|
|
|
my $self=shift; |
106
|
|
|
|
|
|
|
my $group=shift; |
107
|
|
|
|
|
|
|
affirm { $group }; |
108
|
|
|
|
|
|
|
$self->read_cltab; |
109
|
|
|
|
|
|
|
my @raw = @{$self->{raw}}; |
110
|
|
|
|
|
|
|
# warn dump "@raw"; |
111
|
|
|
|
|
|
|
my @proc; |
112
|
|
|
|
|
|
|
for my $raw (@raw) |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
next unless $raw; |
115
|
|
|
|
|
|
|
next unless $raw->{group} eq $group; |
116
|
|
|
|
|
|
|
my $proc = Cluster::Init::Process->new(%$raw); |
117
|
|
|
|
|
|
|
push @proc, $proc; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
return @proc; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# get a configuration variable |
123
|
|
|
|
|
|
|
sub get |
124
|
|
|
|
|
|
|
{ |
125
|
|
|
|
|
|
|
my $self=shift; |
126
|
|
|
|
|
|
|
my $var=shift; |
127
|
|
|
|
|
|
|
# cltab overrides everything |
128
|
|
|
|
|
|
|
$self->read_cltab; |
129
|
|
|
|
|
|
|
return $self->{$var}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub read_cltab |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
my $self=shift; |
135
|
|
|
|
|
|
|
my $cltab = $self->{'cltab'}; |
136
|
|
|
|
|
|
|
unless (-f $cltab) |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
warn "file not found: $cltab\n"; |
139
|
|
|
|
|
|
|
$self->{msg}="file not found: $cltab\n"; |
140
|
|
|
|
|
|
|
$self->{ok}=1; |
141
|
|
|
|
|
|
|
return $self->{ok}; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
my $mtime=(stat($cltab))[9] || die $!; |
144
|
|
|
|
|
|
|
$self->{'cltab_mtime'} = 0 unless $self->{'cltab_mtime'}; |
145
|
|
|
|
|
|
|
return $self->{ok} unless $mtime > $self->{'cltab_mtime'}; |
146
|
|
|
|
|
|
|
$self->{'cltab_mtime'} = $mtime; |
147
|
|
|
|
|
|
|
debug "reading cltab $cltab, PWD is $ENV{PWD}"; |
148
|
|
|
|
|
|
|
my @tag; |
149
|
|
|
|
|
|
|
$self->{ok}=1; |
150
|
|
|
|
|
|
|
$self->{raw}=[]; |
151
|
|
|
|
|
|
|
open(ITAB,"<$cltab") || die $!; |
152
|
|
|
|
|
|
|
while() |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
next if /^#/; |
155
|
|
|
|
|
|
|
next if /^\s*$/; |
156
|
|
|
|
|
|
|
chomp; |
157
|
|
|
|
|
|
|
# deal with master config items |
158
|
|
|
|
|
|
|
if (/^:::(.+?):(.+)$/) |
159
|
|
|
|
|
|
|
{ |
160
|
|
|
|
|
|
|
my ($var,$val) = ($1,$2); |
161
|
|
|
|
|
|
|
$self->{$var}=$val; |
162
|
|
|
|
|
|
|
debug "$var = $val"; |
163
|
|
|
|
|
|
|
next; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
# clients don't need to deal with anything past here |
166
|
|
|
|
|
|
|
next unless $self->{'context'} eq 'server'; |
167
|
|
|
|
|
|
|
my ($group,$tag,$level,$mode,$cmd) = split(':',$_,5); |
168
|
|
|
|
|
|
|
debug "$group $tag $level $mode $cmd"; |
169
|
|
|
|
|
|
|
if (grep /^$tag$/, @tag) |
170
|
|
|
|
|
|
|
{ |
171
|
|
|
|
|
|
|
debug "entry has duplicate tag: $tag"; |
172
|
|
|
|
|
|
|
$self->{msg}="entry has duplicate tag: $tag"; |
173
|
|
|
|
|
|
|
$self->{ok}=0; |
174
|
|
|
|
|
|
|
next; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
push @tag, $tag; |
177
|
|
|
|
|
|
|
my $raw = |
178
|
|
|
|
|
|
|
{ |
179
|
|
|
|
|
|
|
line=>$., |
180
|
|
|
|
|
|
|
group=>$group, |
181
|
|
|
|
|
|
|
tag=>$tag, |
182
|
|
|
|
|
|
|
level=>$level, |
183
|
|
|
|
|
|
|
mode=>$mode, |
184
|
|
|
|
|
|
|
cmd=>$cmd |
185
|
|
|
|
|
|
|
}; |
186
|
|
|
|
|
|
|
${$self->{raw}}[$.]=$raw; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
debug dump $self->{raw}; |
189
|
|
|
|
|
|
|
close ITAB; |
190
|
|
|
|
|
|
|
return $self->{ok}; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |