lib/Rex/Virtualization/VBox/start.pm

filter: Statementstmt 53.1% 25 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 38.8% 33 / 85 CC 11 SCAR 43.4
CC
11
Cov
36%
execute
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 76.8
« lib/Rex/Virtualization/VBox/create.pm ↑ Summary lib/Rex/Virtualization/VBox/share_folder.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Virtualization::VBox::start;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Commands;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Cwd 'getcwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub execute {
Subroutine execute: not called CC=11 SCAR=48.8
Pod undocumented
20 0 my ( $class, $arg1, %opt ) = @_;
21  
22 0 ▶ unless ($arg1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg1) 0 0 0
23 0 die("You have to define the vm name!");
24 }
25  
26 0 my $dom = $arg1;
27 0 Rex::Logger::debug("starting domain: $dom");
28  
29 0 ▶ unless ($dom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dom) 0 0 0
30 0 die("VM $dom not found.");
31 }
32  
33 0 my $virt_settings = Rex::Config->get("virtualization");
34 0 my $headless = 0;
35 0 ▶ if ( ref($virt_settings) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $virt_settings) 0 0 0
36 0 ▶ if ( exists $virt_settings->{headless} && $virt_settings->{headless} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $virt_settings->{"headless"} and $virt_settings->{"headless"}) 0 0 0
Condition0%0/3
exists $virt_settings->{"headless"} and $virt_settings->{"headless"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $virt_settings->{"headless"} and $virt_settings->{"headless"}
exists $virt_settings->{"headless"} $virt_settings->{"headless"}
Truth table0%0/3
A and B
A= exists $virt_settings->{"headless"}B= $virt_settings->{"headless"}
ABresult
0X0
100
111
37 0 $headless = 1;
38 }
39 }
40  
41 0 ▶ if ( $headless && $^O =~ m/^MSWin/ && !Rex::is_ssh() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headless and $^O =~ /^MSWin/u and not Rex::is_ssh()) 0 0 0
Condition0%0/6
$headless and $^O =~ /^MSWin/u and not Rex::is_ssh()
!ll&&!rl&&r
000
$headless and $^O =~ /^MSWin/u
!ll&&!rl&&r
000
MC/DC0%0/3
$headless and $^O =~ /^MSWin/u and not Rex::is_ssh()
$headless $^O =~ /^MSWin/u not Rex::is_ssh()
Truth table0%0/4
A and B and not(C)
A= $headlessB= $^O =~ /^MSWin/uC= not Rex::is_ssh()
ABCresult
0XX0
10X0
1100
1111
42 0 Rex::Logger::info(
43 "Right now it is not possible to run VBoxHeadless under Windows.");
44 0 $headless = 0;
45 }
46  
47 0 ▶ if ($headless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headless) { } 0 0 0
48 0 my $filename = get_tmp_file;
49  
50 0 file( "$filename", content => <<EOF );
51 use POSIX();
52  
53 my \$pid = fork();
54 if (defined \$pid && \$pid == 0 ) {
55 # child
56 chdir "/";
57 umask 0;
58 POSIX::setsid();
59 local \$SIG{'HUP'} = 'IGNORE';
60 my \$spid = fork();
61 if (defined \$spid && \$spid == 0 ) {
62  
63 open( STDIN, "</dev/null" );
64 open( STDOUT, "+>/dev/null" );
65 open( STDERR, "+>/dev/null" );
66  
67 # 2nd child
68 unlink "$filename";
69 exec("VBoxHeadless --startvm \\\"$dom\\\"");
70 exit;
71  
72  
73 }
74  
75 exit; # end first child (2nd parent)
76 }
77 else {
78 waitpid( \$pid, 0 );
79 }
80  
81 exit;
82  
83 EOF
84  
85 0 i_run "perl $filename", fail_ok => 1;
86 }
87 else {
88 0 i_run "VBoxManage startvm \"$dom\"", fail_ok => 1;
89 }
90  
91 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
92 0 die("Error starting vm $dom");
93 }
94  
95 }
96  
97 1 1;
« lib/Rex/Virtualization/VBox/create.pm ↑ Summary lib/Rex/Virtualization/VBox/share_folder.pm »