lib/Illumos/SMF.pm

filter: Statementstmt 8.0% 22 / 274 Branchbran 2.3% 3 / 126 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 11.5% 3 / 26 Podpod 95.4% 21 / 22 totaltotal 9.5% 49 / 513 SCAR 87.9
CC
88
Cov
6%
listFMRI
132.0
getFMRIProperties
132.0
setProperty
110.0
CRAP 6590.9
↑ Summary blib/lib/Illumos/SMF.pm »
1 package Illumos::SMF;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # version
7 1 our $VERSION = '0.1.6';
8  
9 # commands
10 1 my $SVCS = '/usr/bin/svcs';
11 1 my $SVCCFG = '/usr/sbin/svccfg';
12 1 my $SVCADM = '/usr/sbin/svcadm';
13 1 my $ZLOGIN = '/usr/sbin/zlogin';
14  
15 # constructor
16 sub new {
17 2 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
18 2 my $self = { @_ };
19  
20 # add Illumos::Zone instance if zone support is required
21 2 ▶ $self->{zonesupport} && do {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"zonesupport"} and do { eval { do { require Illumos::Zones } }; if ($@) { die "ERROR: Unable to load package Illumos::Zones."; } ; $self->{"zone"} = "Illumos::Zones"->new("debug", $self->{"debug"}) } 1 1 2
22 1 eval {
23 1 require Illumos::Zones;
24 };
25 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
26 0 die "ERROR: Unable to load package Illumos::Zones.";
27 }
28  
29 1 $self->{zone} = Illumos::Zones->new(debug => $self->{debug});
30 };
31
32 2 return bless $self, $class
33 }
34 # private methods
35 my $svcAdm = sub {
36 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
37 0 my $cmd = shift;
38 0 my $fmri = shift;
39  
40 0 my @cmd = ($SVCADM, $cmd, $fmri);
41  
42 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
43 0 ▶ system(@cmd) and die "ERROR: cannot $cmd '$fmri'\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot $cmd '${fmri}'\n" 0 0 0
44 1 };
45  
46 my $zoneCmd = sub {
47 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=7 SCAR=40.3
48 0 my $zoneName = shift;
49  
50 print STDERR "WARNING: zonename specified but 'zonesupport' not enabled for Illumos::SMF\n"
51 0 ▶ . "use 'Illumos::SMF(zonesupport => 1)' to enable zone support\n" if $zoneName && !$self->{zone};
Branch: 1 branch
BranchTrueFalseTotal
if $zoneName and not $self->{"zone"} 0 0 0
Condition0%0/3
$zoneName and not $self->{"zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
$zoneName and not $self->{"zone"}
$zoneName not $self->{"zone"}
Truth table0%0/3
A and not(B)
A= $zoneNameB= not $self->{"zone"}
ABresult
0X0
100
111
52  
53 0 ▶ return { cmd => [], shellquote => q{"} } if !$zoneName || !$self->{zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $zoneName and $self->{"zone"} 0 0 0
Condition0%0/3
$zoneName and $self->{"zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
$zoneName and $self->{"zone"}
$zoneName $self->{"zone"}
Truth table0%0/3
A and B
A= $zoneNameB= $self->{"zone"}
ABresult
0X0
100
111
54  
55 0 my $zone = $self->{zone}->listZone($zoneName);
56 0 ▶ if ($zone && $zone->{state} eq 'running') {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone and $zone->{'state'} eq 'running') { } 0 0 0
Condition0%0/3
$zone and $zone->{"state"} eq "running"
!ll&&!rl&&r
000
MC/DC0%0/2
$zone and $zone->{"state"} eq "running"
$zone $zone->{"state"} eq "running"
Truth table0%0/3
A and B
A= $zoneB= $zone->{"state"} eq "running"
ABresult
0X0
100
111
57 0 return { cmd => [ $ZLOGIN, $zoneName ], shellquote => q{'"'} };
58 }
59 else {
60 0 return { cmd => [], zpath => $zone->{zonepath}, shellquote => q{"} };
61 }
62  
63 # just in case, should never reach here...
64 0 return { cmd => [], shellquote => q{"} };
65 1 };
66  
67 # public methods
68 sub refreshFMRI {
69 0 ▶ my $self = shift;
Subroutine refreshFMRI: not called CC=5 SCAR=34.0
Pod documented
70 0 my $fmri = shift;
71 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
72
73 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
74 0 my @cmd = @{$zcmd->{cmd}};
75 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
76 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
77  
78 0 push @cmd, ($SVCCFG, '-s', $fmri, 'refresh');
79  
80 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
81 0 ▶ system(@cmd) and die "ERROR: cannot refresh FMRI '$fmri'\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot refresh FMRI '${fmri}'\n" 0 0 0
82
83 0 return 1;
84 }
85  
86 sub listFMRI {
87 0 ▶ my $self = shift;
Subroutine listFMRI: not called CC=11 SCAR=48.8
Pod documented
88 0 my $fmri = shift;
89 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
90 0 my @fmris;
91
92 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
93 0 my @cmd = @{$zcmd->{cmd}};
94 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
95 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
96
97 0 ▶ $fmri ||= '*';
Condition0%0/2
$fmri ||= "*"
l!l
00
MC/DC0%0/1
$fmri ||= "*"
$fmri
Truth table0%0/2
A
A= $fmri
Aresult
11
00
98
99 # remove leading 'svc:/'
100 0 $fmri =~ s/^svc:\///;
101  
102 0 my @cmd1 = (@cmd, $SVCCFG, 'list', $fmri);
103  
104 0 ▶ print STDERR '# ' . join(' ', @cmd1) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
105 0 ▶ open my $fmris, '-|', @cmd1
Branch: 1 branch
BranchTrueFalseTotal
open my $fmris, "-|", @cmd1 or die "ERROR: cannot get list of FMRI\n" 0 0 0
106 or die "ERROR: cannot get list of FMRI\n";
107  
108 0 ▶ while (my $elem = <$fmris>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $elem = readline $fmris)) 0 0 0
109 0 chomp $elem;
110 0 ▶ push @fmris, "svc:/$elem" if !$opts->{instancesonly};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"instancesonly"} 0 0 0
111
112 0 my @cmd2 = (@cmd, $SVCCFG, '-s', $elem, 'list');
113  
114 0 ▶ open my $instances, '-|', @cmd2
Branch: 1 branch
BranchTrueFalseTotal
open my $instances, "-|", @cmd2 or die "ERROR: cannot get instances of '${elem}'\n" 0 0 0
115 or die "ERROR: cannot get instances of '$elem'\n";
116  
117 0 ▶ while (<$instances>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $instances)) 0 0 0
118 0 chomp;
119 0 ▶ next if /:properties/;
Branch: 1 branch
BranchTrueFalseTotal
if /:properties/ 0 0 0
120 0 push @fmris, "svc:/$elem:$_";
121 }
122 0 close $instances;
123 }
124  
125 0 return [ @fmris ];
126 }
127  
128 sub fmriExists {
129 0 ▶ my $self = shift;
Subroutine fmriExists: not called CC=1 SCAR=6.9
Pod documented
130 0 my $fmri = shift;
131 0 my $opts = shift;
132  
133 # remove instance name
134 0 my ($baseFmri) = $fmri =~ /^((?:svc:)?[^:]+)/;
135  
136 0 return grep { $fmri eq $_ } @{$self->listFMRI($baseFmri, $opts)};
137 }
138  
139 sub fmriState {
140 0 ▶ my $self = shift;
Subroutine fmriState: not called CC=4 SCAR=30.0
Pod documented
141 0 my $fmri = shift;
142 0 my $opts = shift;
143  
144 0 ▶ my @cmd = ($SVCS, $opts->{zonename} ? ('-z', $opts->{zonename}) : (), qw(-H -o state), $fmri);
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'zonename'} ? : 0 0 0
145  
146 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
147 0 ▶ open my $fmris, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $fmris, "-|", @cmd or die "ERROR: cannot get list of FMRI\n" 0 0 0
148 or die "ERROR: cannot get list of FMRI\n";
149  
150 0 chomp(my $state = <$fmris>);
151 0 return $state;
152 }
153  
154 sub fmriOnline {
155 0 ▶ my $self = shift;
Subroutine fmriOnline: not called CC=1 SCAR=6.9
Pod documented
156
157 0 return $self->fmriState(shift, shift) eq 'online';
158 }
159  
160 sub enable {
161 0 ▶ my $self = shift;
Subroutine enable: not called CC=1 SCAR=6.9
Pod documented
162 0 my $fmri = shift;
163  
164 0 $self->$svcAdm('enable', $fmri);
165 }
166  
167 sub disable {
168 0 ▶ my $self = shift;
Subroutine disable: not called CC=1 SCAR=6.9
Pod documented
169 0 my $fmri = shift;
170  
171 0 $self->$svcAdm('disable', $fmri);
172 }
173  
174 sub restart {
175 0 ▶ my $self = shift;
Subroutine restart: not called CC=1 SCAR=6.9
Pod documented
176 0 my $fmri = shift;
177  
178 0 $self->$svcAdm('restart', $fmri);
179 }
180  
181 sub addFMRI {
182 0 ▶ my $self = shift;
Subroutine addFMRI: not called CC=5 SCAR=34.0
Pod documented
183 0 my $fmri = shift;
184 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
185  
186 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
187 0 my @cmd = @{$zcmd->{cmd}};
188 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
189 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
190  
191 # remove leading 'svc:/'
192 0 $fmri =~ s/^svc:\///;
193  
194 0 push @cmd, ($SVCCFG, 'add', $fmri);
195  
196 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
197 0 ▶ system(@cmd) and die "ERROR: cannot add '$fmri'\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot add '${fmri}'\n" 0 0 0
198 }
199  
200 sub deleteFMRI {
201 0 ▶ my $self = shift;
Subroutine deleteFMRI: not called CC=5 SCAR=34.0
Pod documented
202 0 my $fmri = shift;
203 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
204  
205 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
206 0 my @cmd = @{$zcmd->{cmd}};
207 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
208 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
209  
210 0 push @cmd, ($SVCCFG, 'delete', $fmri);
211 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
212 0 ▶ system(@cmd) and die "ERROR: cannot delete $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot delete $fmri\n" 0 0 0
213 }
214  
215 sub addInstance {
216 0 ▶ my $self = shift;
Subroutine addInstance: not called CC=6 SCAR=37.4
Pod documented
217 0 my $fmri = shift;
218 0 my $instance = shift;
219 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
220  
221 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
222 0 my @cmd = @{$zcmd->{cmd}};
223 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
224 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
225  
226 0 push @cmd, ($SVCCFG, '-s', $fmri, 'add', $instance);
227 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
228 0 ▶ system(@cmd) and die "ERROR: cannot add instance '$instance' to $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot add instance '${instance}' to $fmri\n" 0 0 0
229  
230 0 $self->addPropertyGroup("$fmri:$instance", 'general', 'framework', $opts);
231 0 $self->setProperty("$fmri:$instance", 'general/complete', $instance, undef, $opts);
232 $self->setProperty("$fmri:$instance", 'general/enabled',
233 0 ▶ $opts->{enabled} ? 'true' : 'false', undef, $opts);
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'enabled'} ? : 0 0 0
234 }
235  
236 sub getPropertyGroups {
237 0 ▶ my $self = shift;
Subroutine getPropertyGroups: not called CC=6 SCAR=37.4
Pod documented
238 0 my $fmri = shift;
239 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
240  
241 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
242 0 my @cmd = @{$zcmd->{cmd}};
243 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
244 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
245  
246 0 my $pg = [];
247 0 push @cmd, ($SVCCFG, '-s', $fmri, 'listpg');
248  
249 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
250 0 ▶ open my $props, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $props, "-|", @cmd or die "ERROR: cannot get property group of FMRI '${fmri}'\n" 0 0 0
251 or die "ERROR: cannot get property group of FMRI '$fmri'\n";
252  
253 0 ▶ while (my $prop = <$props>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prop = readline $props)) 0 0 0
254 0 chomp $prop;
255 0 my ($name, $type) = split /\s+/, $prop, 2;
256 0 push @$pg, $name;
257 }
258
259 0 return $pg;
260 }
261  
262 sub propertyExists {
263 0 ▶ my $self = shift;
Subroutine propertyExists: not called CC=1 SCAR=6.9
Pod documented
264 0 my $fmri = shift;
265 0 my $property = shift;
266 0 my $opts = shift;
267
268 # extract property group
269 0 my ($pg) = $property =~ /^([^\/]+)/;
270  
271 0 return grep { $property eq $_ } keys %{$self->getProperties($fmri, $pg, $opts)};
272 }
273  
274 sub propertyGroupExists {
275 0 ▶ my $self = shift;
Subroutine propertyGroupExists: not called CC=1 SCAR=6.9
Pod documented
276 0 my $fmri = shift;
277 0 my $pg = shift;
278 0 my $opts = shift;
279  
280 0 return grep { $pg eq $_ } @{$self->getPropertyGroups($fmri, $opts)};
281 }
282  
283 sub addPropertyGroup {
284 0 ▶ my $self = shift;
Subroutine addPropertyGroup: not called CC=7 SCAR=40.3
Pod documented
285 0 my $fmri = shift;
286 0 my $pg = shift;
287 0 my $type = shift;
288 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
289
290 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
291 0 my @cmd = @{$zcmd->{cmd}};
292 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
293 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
294
295 # set type to application if not specified
296 0 ▶ $type //= 'application';
Condition0%0/2
$type //= "application"
l!l
00
MC/DC0%0/1
$type //= "application"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
297  
298 0 ▶ return if $self->propertyGroupExists($fmri, $pg, $opts);
Branch: 1 branch
BranchTrueFalseTotal
if $self->propertyGroupExists($fmri, $pg, $opts) 0 0 0
299  
300 0 push @cmd, ($SVCCFG, '-s', $fmri, 'addpg', $pg, $type);
301 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
302 0 ▶ system(@cmd) and die "ERROR: cannot add property group to $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot add property group to $fmri\n" 0 0 0
303 }
304  
305 sub deletePropertyGroup {
306 0 ▶ my $self = shift;
Subroutine deletePropertyGroup: not called CC=5 SCAR=34.0
Pod documented
307 0 my $fmri = shift;
308 0 my $pg = shift;
309 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
310
311 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
312 0 my @cmd = @{$zcmd->{cmd}};
313 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
314 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
315
316 0 push @cmd, ($SVCCFG, '-s', $fmri, 'delpg', $pg);
317 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
318 0 ▶ system(@cmd) and die "ERROR: cannot delete property group from $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot delete property group from $fmri\n" 0 0 0
319 }
320  
321 sub setProperty {
322 0 ▶ my $self = shift;
Subroutine setProperty: not called CC=10 SCAR=47.0
Pod documented
323 0 my $fmri = shift;
324 0 my $property = shift;
325 0 my $value = shift;
326 0 my $type = shift;
327 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
328
329 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
330 0 my @cmd = @{$zcmd->{cmd}};
331 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
332 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
333  
334 # guess property type if not provided
335 0 ▶ $type || do {
Branch: 1 branch
BranchTrueFalseTotal
$type or do { $type = "astring"; foreach $_ ($value) { /^\d+$/ and do { $type = "count"; last }; /^(?:true|false)$/i and do { $type = "boolean"; last }; } } 0 0 0
336 0 $type = 'astring';
337  
338 0 for ($value){
339 0 ▶ /^\d+$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^\d+$/ and do { $type = "count"; last } 0 0 0
340 0 $type = 'count';
341 0 last;
342 };
343  
344 0 ▶ /^(?:true|false)$/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/^(?:true|false)$/i and do { $type = "boolean"; last } 0 0 0
345 0 $type = 'boolean';
346 0 last;
347 };
348 }
349 };
350  
351 push @cmd, $self->propertyExists($fmri, $property, $opts) ?
352 ($SVCCFG, '-s', $fmri, 'setprop', $property, '=',
353 $zcmd->{shellquote} . $value . $zcmd->{shellquote})
354 : ($SVCCFG, '-s', $fmri, 'addpropvalue', $property, "$type:",
355 0 ▶ $zcmd->{shellquote} . $value . $zcmd->{shellquote});
Branch: 1 branch
BranchTrueFalseTotal
$self->propertyExists($fmri, $property, $opts) ? : 0 0 0
356 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
357 0 ▶ system(@cmd) and die "ERROR: cannot set property $property of $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot set property $property of $fmri\n" 0 0 0
358 }
359  
360 sub setProperties {
361 0 ▶ my $self = shift;
Subroutine setProperties: not called CC=2 SCAR=17.9
Pod documented
362 0 my $fmri = shift;
363 0 my $properties = shift;
364 0 my $opts = shift;
365  
366 0 for my $key (keys %$properties){
367 0 $self->setProperty($fmri, $key, $properties->{$key}, undef, $opts)
368 }
369 }
370  
371 sub getProperties {
372 0 ▶ my $self = shift;
Subroutine getProperties: not called CC=7 SCAR=40.3
Pod documented
373 0 my $fmri = shift;
374 0 my $pg = shift;
375 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
376
377 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
378 0 my @cmd = @{$zcmd->{cmd}};
379 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
380 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
381  
382 0 my $properties = {};
383  
384 0 push @cmd, ($SVCCFG, '-s', $fmri, 'listprop', $pg);
385  
386 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
387 0 ▶ open my $props, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $props, "-|", @cmd or die "ERROR: cannot get properties of FMRI '${fmri}'\n" 0 0 0
388 or die "ERROR: cannot get properties of FMRI '$fmri'\n";
389  
390 0 ▶ while (<$props>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $props)) 0 0 0
391 0 chomp;
392 0 my ($name, $type, $value) = split /\s+/, $_, 3;
393 0 ▶ next if $name eq $pg;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $pg 0 0 0
394 #remove quotes
395 0 $value =~ s/^"|"$//g;
396 0 $properties->{$name} = $value;
397  
398 }
399
400 0 return $properties;
401 }
402  
403 sub setFMRIProperties {
404 0 ▶ my $self = shift;
Subroutine setFMRIProperties: not called CC=7 SCAR=40.3
Pod documented
405 0 my $fmri = shift;
406 0 my $properties = shift;
407 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
408
409 0 ▶ $self->addFMRI($fmri, $opts) if !$self->fmriExists($fmri, $opts);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fmriExists($fmri, $opts) 0 0 0
410 # extract property groups
411 0 ▶ my @pg = map { $properties->{$_}->{members} ? $_ : () } keys %$properties;
Branch: 1 branch
BranchTrueFalseTotal
$properties->{$_}{'members'} ? : 0 0 0
412  
413 0 for my $pg (@pg) {
414 0 $self->addPropertyGroup($fmri, $pg, $properties->{$pg}->{type}, $opts);
415 0 for my $prop (keys %{$properties->{$pg}->{members}}) {
416 $self->setProperty($fmri, "$pg/$prop",
417 $properties->{$pg}->{members}->{$prop}->{value},
418 $properties->{$pg}->{members}->{$prop}->{type},
419 0 $opts);
420 }
421 0 delete $properties->{$pg};
422 }
423  
424 0 for my $prop (keys %$properties) {
425 $self->setProperty($fmri, $prop,
426 $properties->{$prop}->{value},
427 $properties->{$prop}->{type},
428 0 $opts);
429 }
430 }
431  
432 sub getFMRIProperties {
433 0 ▶ my $self = shift;
Subroutine getFMRIProperties: not called CC=11 SCAR=48.8
Pod documented
434 0 my $fmri = shift;
435 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
436
437 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
438 0 my @cmd = @{$zcmd->{cmd}};
439 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
440 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
441  
442 0 my $properties = {};
443  
444 0 push @cmd, ($SVCCFG, '-s', $fmri, 'listprop');
445  
446 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
447 0 ▶ open my $props, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $props, "-|", @cmd or die "ERROR: cannot get properties of FMRI\n" 0 0 0
448 or die "ERROR: cannot get properties of FMRI\n";
449  
450 0 ▶ while (<$props>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $props)) 0 0 0
451 0 chomp;
452 0 my ($pg, $prop, $type, $value) = /^(?:([-\w]+)\/)?([-\w]+)\s+([-\w]+)(?:\s+(.+))?$/;
453 0 ▶ next if !$prop || !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $prop and $type 0 0 0
Condition0%0/3
$prop and $type
!ll&&!rl&&r
000
MC/DC0%0/2
$prop and $type
$prop $type
Truth table0%0/3
A and B
A= $propB= $type
ABresult
0X0
100
111
454 # remove quotes from $value
455 0 ▶ $value =~ s/^"|"$//g if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
456 0 ▶ if ($pg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pg) { } 0 0 0
457 0 $properties->{$pg}->{members}->{$prop}->{type} = $type;
458 0 $properties->{$pg}->{members}->{$prop}->{value} = $value;
459 }
460 else {
461 0 $properties->{$prop}->{type} = $type;
462 0 ▶ $properties->{$prop}->{value} = $value // '';
Condition0%0/2
$value // ""
l!l
00
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
463 }
464 }
465  
466 0 return $properties;
467 }
468  
469 1 1;
470  
471 __END__
↑ Summary blib/lib/Illumos/SMF.pm »