| 1 | package MySQL::Sandbox; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 24 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 24 | ▶ | use base qw( Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 24 | our @ISA= qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 24 | our @EXPORT_OK= qw( is_port_open | |||||||||||||||||||||||||||||||||||||||||
| 13 | runs_as_root | ||||||||||||||||||||||||||||||||||||||||||
| 14 | mylogin_cnf_exists | ||||||||||||||||||||||||||||||||||||||||||
| 15 | exists_in_path | ||||||||||||||||||||||||||||||||||||||||||
| 16 | is_a_sandbox | ||||||||||||||||||||||||||||||||||||||||||
| 17 | find_safe_port_and_directory | ||||||||||||||||||||||||||||||||||||||||||
| 18 | first_unused_port | ||||||||||||||||||||||||||||||||||||||||||
| 19 | get_sandbox_params | ||||||||||||||||||||||||||||||||||||||||||
| 20 | is_sandbox_running | ||||||||||||||||||||||||||||||||||||||||||
| 21 | get_sb_info | ||||||||||||||||||||||||||||||||||||||||||
| 22 | get_ports | ||||||||||||||||||||||||||||||||||||||||||
| 23 | get_ranges | ||||||||||||||||||||||||||||||||||||||||||
| 24 | use_env | ||||||||||||||||||||||||||||||||||||||||||
| 25 | sbinstr | ||||||||||||||||||||||||||||||||||||||||||
| 26 | get_json_from_dirs | ||||||||||||||||||||||||||||||||||||||||||
| 27 | get_option_file_contents | ||||||||||||||||||||||||||||||||||||||||||
| 28 | validate_json_object | ||||||||||||||||||||||||||||||||||||||||||
| 29 | fix_server_uuid | ||||||||||||||||||||||||||||||||||||||||||
| 30 | greater_version | ||||||||||||||||||||||||||||||||||||||||||
| 31 | split_version | ||||||||||||||||||||||||||||||||||||||||||
| 32 | deprecation_notice | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ) ; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 24 | our $VERSION=q{3.2.18}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 24 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 24 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=14 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 24 | ▶ | $DEBUG = $ENV{'SBDEBUG'} || $ENV{'SBVERBOSE'} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$ENV{'SBDEBUG'} || $ENV{'SBVERBOSE'} || 0
$ENV{"SBDEBUG"} or $ENV{"SBVERBOSE"}
MC/DC0%0/2
$ENV{'SBDEBUG'} || $ENV{'SBVERBOSE'} || 0
$ENV{"SBDEBUG"}
$ENV{"SBVERBOSE"}
Truth table33%1/3
A or B
A= $ENV{"SBDEBUG"}B= $ENV{"SBVERBOSE"}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 24 | ▶ | if (! $ENV{'USER'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 24 | my $user = qx/whoami/; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 24 | chomp $user; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 24 | $ENV{'USER'} = $user; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 24 | for my $var (qw( HOME USER PWD )) | |||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 72 | ▶ | unless ($ENV{$var}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | die "The variable \$$var is undefined - aborting\n"; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 24 | ▶ | if ($ENV{HOME} =~ /\s/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | die "# The variable \$HOME contains spaces. Please fix this problem before continuing\n(HOME='$ENV{HOME}')\n"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 24 | ▶ | unless ( $ENV{SANDBOX_HOME} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 24 | $ENV{SANDBOX_HOME} = "$ENV{HOME}/sandboxes"; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 24 | ▶ | unless ($ENV{TMPDIR}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 24 | $ENV{TMPDIR} = '/tmp'; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 24 | ▶ | unless ( -d $ENV{TMPDIR}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | die "could not find $ENV{TMPDIR}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 24 | ▶ | if ( -d "$ENV{HOME}/sandboxes" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $ENV{SANDBOX_HOME} = $ENV{SANDBOX_HOME} || "$ENV{HOME}/sandboxes"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'SANDBOX_HOME'} || "$ENV{'HOME'}/sandboxes"
MC/DC0%0/1
$ENV{'SANDBOX_HOME'} || "$ENV{'HOME'}/sandboxes"
$ENV{'SANDBOX_HOME'}
Truth table0%0/2
A
A= $ENV{'SANDBOX_HOME'}
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 24 | ▶ | unless ( $ENV{SANDBOX_BINARY} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 24 | ▶ | if ( -d "$ENV{HOME}/opt/mysql") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $ENV{SANDBOX_BINARY} = "$ENV{HOME}/opt/mysql"; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | else | ||||||||||||||||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 24 | $ENV{SANDBOX_BINARY} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 24 | my @supported_versions = qw( 3.23 4.0 4.1 5.0 5.1 5.2 5.3 5.4 | |||||||||||||||||||||||||||||||||||||||||
| 85 | 5.5 5.6 5.7 6.0 7.0 7.1 7.2 7.3 7.4 7.5 7.6 8.0 10.0 10.1 10.2 10.3 10.4 ); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 24 | our $sandbox_options_file = "my.sandbox.cnf"; | |||||||||||||||||||||||||||||||||||||||||
| 88 | # our $sandbox_current_options = "current_options.conf"; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 24 | our %default_base_port = ( | |||||||||||||||||||||||||||||||||||||||||
| 91 | replication => 11000, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | circular => 14000, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | multiple => 7000, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | custom => 5000, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | our %default_users = ( | |||||||||||||||||||||||||||||||||||||||||
| 98 | db_user => 'msandbox', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | remote_access => '127.%', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | db_password => 'msandbox', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ro_user => 'msandbox_ro', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | rw_user => 'msandbox_rw', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | repl_user => 'rsandbox', | ||||||||||||||||||||||||||||||||||||||||||
| 104 | repl_password => 'rsandbox', | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | our $SBINSTR_SH_TEXT =<<'SBINSTR_SH_TEXT'; | |||||||||||||||||||||||||||||||||||||||||
| 108 | if [ -f "$SBINSTR" ] | ||||||||||||||||||||||||||||||||||||||||||
| 109 | then | ||||||||||||||||||||||||||||||||||||||||||
| 110 | echo "[`basename $0`] - `date "+%Y-%m-%d %H:%M:%S"` - $@" >> $SBINSTR | ||||||||||||||||||||||||||||||||||||||||||
| 111 | fi | ||||||||||||||||||||||||||||||||||||||||||
| 112 | SBINSTR_SH_TEXT | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 119 | parse_options => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | options => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # my $version = get_version( $install_dir); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # $self->{version} = $VERSION; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub parse_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_options: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my ($self, $opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | # print "<", ref($opt) , ">\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | unless (ref($opt) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | confess "parse_options must be a hash reference\n"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($opt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $self->{parse_options} = $opt; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my %options = map { $_ , $opt->{$_}{'value'}} keys %{$opt}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->{options} = \%options; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return $self->{options}; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub find_safe_port_and_directory { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_safe_port_and_directory: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my ($wanted_port, $wanted_dir, $upper_directory) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $chosen_port = $wanted_port; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($ports, undef) = get_sb_info( $ENV{SANDBOX_HOME}, undef); | |||||||||||||||||||||||||||||||||||||||||
| 146 | # print Dumper($ports); | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | while ( is_port_open($chosen_port) or exists $ports->{$chosen_port}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_port_open($chosen_port) or exists $ports->{$chosen_port}
MC/DC0%0/2
is_port_open($chosen_port) or exists $ports->{$chosen_port}
is_port_open($chosen_port)
exists $ports->{$chosen_port}
Truth table0%0/3
A or B
A= is_port_open($chosen_port)B= exists $ports->{$chosen_port}
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $chosen_port++; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $chosen_port = first_unused_port($chosen_port); | |||||||||||||||||||||||||||||||||||||||||
| 150 | # print "checking -> $chosen_port\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $suffix = 'a'; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $chosen_dir = $wanted_dir; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | while ( -d "$upper_directory/$chosen_dir" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | # print "checking -> $chosen_dir\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $chosen_dir = $wanted_dir . '_' . $suffix; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $suffix++; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return ($chosen_port, $chosen_dir); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub deprecation_notice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deprecation_notice: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | print "#############################################################################\n"; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | print "# IMPORTANT NOTICE #\n"; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | print "# ------------------------------------------------------------------------- #\n"; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | print "# MySQL-Sandbox is NOT MAINTAINED anymore. #\n"; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | print "# It may fail on recent MySQL versions. #\n"; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | print "# You should use **dbdeployer** (https://github.com/datacharmer/dbdeployer) #\n"; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | print "#############################################################################\n"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub get_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_help: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($msg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | warn "[***] $msg\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $HELP_MSG = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | for my $op ( | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | sort { $self->{parse_options}->{$a}{so} <=> $self->{parse_options}->{$b}{so} } | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | grep { $self->{parse_options}->{$_}{parse}} keys %{ $self->{parse_options} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $param = $self->{parse_options}->{$op}{parse}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $param_str = q{ }; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my ($short, $long ) = $param =~ / (?: (\w) \| )? (\S+) /x; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($short) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $param_str .= q{-} . $short . q{ }; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $long =~ s/ = s \@? / = name/x; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $long =~ s/ = i / = number/x; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $param_str .= q{--} . $long; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $lparam = 40 - length($param_str); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($lparam < 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $lparam = 0; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $param_str .= (q{ } x $lparam ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $text_items = $self->{parse_options}->{$op}{help}; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | for my $titem (@{$text_items}) { | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $HELP_MSG .= $param_str . $titem . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $param_str = q{ } x 40; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if (@{$text_items} > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $HELP_MSG .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # $HELP_MSG .= "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | my $VAR_HELP = | ||||||||||||||||||||||||||||||||||||||||||
| 210 | "\nVARIABLES affecting this program: \n" | ||||||||||||||||||||||||||||||||||||||||||
| 211 | . "\t\$SBDEBUG : DEBUG LEVEL (" | ||||||||||||||||||||||||||||||||||||||||||
| 212 | . ($ENV{SBDEBUG} || 0) . ")\n" | ||||||||||||||||||||||||||||||||||||||||||
| 213 | . "\t\$SBVERBOSE : DEBUG LEVEL (same as \$SBDEBUG) (" | ||||||||||||||||||||||||||||||||||||||||||
| 214 | . ($ENV{SBVERBOSE} || 0) . ")\n" | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | . "\t\$SANDBOX_HOME : root of all sandbox installations (" | ||||||||||||||||||||||||||||||||||||||||||
| 217 | . use_env($ENV{SANDBOX_HOME}) . ")\n" | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | . "\t\$SANDBOX_BINARY : where to search for binaries (" | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | . use_env($ENV{SANDBOX_BINARY}) . ")\n" | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$ENV{'SBDEBUG'} || 0
$ENV{'SBVERBOSE'} || 0
MC/DC0%0/1
$ENV{'SBDEBUG'} || 0
$ENV{'SBDEBUG'}
MC/DC0%0/1
$ENV{'SBVERBOSE'} || 0
$ENV{'SBVERBOSE'}
Truth table0%0/2
A
A= $ENV{'SBDEBUG'}
Truth table0%0/2
A
A= $ENV{'SBVERBOSE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ( $PROGRAM_NAME =~ /replication|multiple/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | $VAR_HELP .= | ||||||||||||||||||||||||||||||||||||||||||
| 225 | "\t\$NODE_OPTIONS : options to pass to all node installations (" | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | . ($ENV{NODE_OPTIONS} || '') . ")\n" | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'NODE_OPTIONS'} || ''
MC/DC0%0/1
$ENV{'NODE_OPTIONS'} || ''
$ENV{'NODE_OPTIONS'}
Truth table0%0/2
A
A= $ENV{'NODE_OPTIONS'}
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ( $PROGRAM_NAME =~ /replication/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | $VAR_HELP .= | ||||||||||||||||||||||||||||||||||||||||||
| 231 | "\t\$MASTER_OPTIONS : options to pass to the master installation (" | ||||||||||||||||||||||||||||||||||||||||||
| 232 | . ($ENV{MASTER_OPTIONS} || '') . ")\n" | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | . "\t\$SLAVE_OPTIONS : options to pass to all slave installations (" | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | . ($ENV{SLAVE_OPTIONS} || '' ) . ")\n" | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$ENV{'MASTER_OPTIONS'} || ''
$ENV{'SLAVE_OPTIONS'} || ''
MC/DC0%0/1
$ENV{'MASTER_OPTIONS'} || ''
$ENV{'MASTER_OPTIONS'}
MC/DC0%0/1
$ENV{'SLAVE_OPTIONS'} || ''
$ENV{'SLAVE_OPTIONS'}
Truth table0%0/2
A
A= $ENV{'MASTER_OPTIONS'}
Truth table0%0/2
A
A= $ENV{'SLAVE_OPTIONS'}
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $target = ''; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( grep {$PROGRAM_NAME =~ /$_/ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | qw( make_sandbox make_replication_sandbox | ||||||||||||||||||||||||||||||||||||||||||
| 240 | make_multiple_sandbox make_multiple_sandbox ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 241 | { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $target = '{tarball|dir|version}'; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $HELP_MSG = | |||||||||||||||||||||||||||||||||||||||||
| 244 | "tarball = the full path to a MySQL binary tarball\n" | ||||||||||||||||||||||||||||||||||||||||||
| 245 | . "dir = the path to an expanded MySQL binary tarball\n" | ||||||||||||||||||||||||||||||||||||||||||
| 246 | . "version = the simple version number of the expanded tarball\n" | ||||||||||||||||||||||||||||||||||||||||||
| 247 | . " if it is under \$SANDBOX_BINARY and renamed as the\n " | ||||||||||||||||||||||||||||||||||||||||||
| 248 | . " version number.\n\n" | ||||||||||||||||||||||||||||||||||||||||||
| 249 | . $HELP_MSG; | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | deprecation_notice(); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | print $self->credits(), | |||||||||||||||||||||||||||||||||||||||||
| 253 | "syntax: $PROGRAM_NAME [options] $target \n", | ||||||||||||||||||||||||||||||||||||||||||
| 254 | $HELP_MSG, | ||||||||||||||||||||||||||||||||||||||||||
| 255 | $VAR_HELP; | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # This example is only relevant for a single sandbox, but it is | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # wrong for a multiple sandbox. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | #, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | #"\nExample:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 260 | #" $PROGRAM_NAME --my_file=large --sandbox_directory=my_sandbox\n\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | deprecation_notice(); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | exit(1); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | sub credits { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
credits: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my $CREDITS = | |||||||||||||||||||||||||||||||||||||||||
| 269 | qq( The MySQL Sandbox, version $VERSION\n) | ||||||||||||||||||||||||||||||||||||||||||
| 270 | . qq( (C) 2006-2018 Giuseppe Maxia\n); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | return $CREDITS; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | sub split_version | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_version: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 277 | #if ($v =~ /(?<major>\d+)\.(?<minor>\d+)\.(?<rev>\d+)/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ($v =~ /(\d+)\.(\d+)\.(\d+)/ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | #return ($+{major}, $+{minor}, $+{rev}) | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return ($1, $2, $3) | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | else | ||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | die "# Split version: could not get components from <$v>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | sub greater_version | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
greater_version: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my ($v1, $v2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my ($v1_major, $v1_minor, $v1_rev) = split_version($v1); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my ($v2_major, $v2_minor, $v2_rev) = split_version($v2); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if ( $v1_major > $v2_major) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | { | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | ▶ | elsif ( ($v1_major == $v2_major) && ($v1_minor > $v2_minor)) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$v1_major == $v2_major and $v1_minor > $v2_minor
MC/DC0%0/2
$v1_major == $v2_major and $v1_minor > $v2_minor
$v1_major == $v2_major
$v1_minor > $v2_minor
Truth table0%0/3
A and B
A= $v1_major == $v2_majorB= $v1_minor > $v2_minor
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | ▶ | elsif ( ($v1_major == $v2_major) && ($v1_minor == $v2_minor) && ($v1_rev > $v2_rev) ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$v1_major == $v2_major and $v1_minor == $v2_minor and $v1_rev > $v2_rev
$v1_major == $v2_major and $v1_minor == $v2_minor
MC/DC0%0/3
$v1_major == $v2_major and $v1_minor == $v2_minor and $v1_rev > $v2_rev
$v1_major == $v2_major
$v1_minor == $v2_minor
$v1_rev > $v2_rev
Truth table0%0/4
A and B and C
A= $v1_major == $v2_majorB= $v1_minor == $v2_minorC= $v1_rev > $v2_rev
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return 0 | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | sub fix_server_uuid | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fix_server_uuid: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my ($server_id, $version, $port, $sandbox_directory) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ($version =~ /(\d+)\.(\d+)/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ($major, $minor ) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | unless ( ($major == 8) or ( ($major == 5) && ($minor >=6)) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$major == 8 or $major == 5 and $minor >= 6
$major == 5 and $minor >= 6
MC/DC0%0/3
$major == 8 or $major == 5 and $minor >= 6
$major == 8
$major == 5
$minor >= 6
Truth table0%0/4
A or B and C
A= $major == 8B= $major == 5C= $minor >= 6
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $current_dir = $ENV{PWD}; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $increase_id = 0; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $sandbox_directory =~ s{/$}{}; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $operation_dir= "$sandbox_directory/data"; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ( ! -d $operation_dir) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | die "<$operation_dir> not found\n"; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | chdir $operation_dir; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | print "# operation_dir is $operation_dir\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ( ($operation_dir =~ m{/node\d/data$}) && (-d "../../master")) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$operation_dir =~ m[/node\d/data$] and -d "../../master"
MC/DC0%0/2
$operation_dir =~ m[/node\d/data$] and -d "../../master"
$operation_dir =~ m[/node\d/data$]
-d "../../master"
Truth table0%0/3
A and B
A= $operation_dir =~ m[/node\d/data$]B= -d "../../master"
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $increase_id =1; | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # 12345678 1234 1234 1234 123456789012 | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # my $new_uuid='00000000-0000-0000-0000-000000000000'; | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $group1 = sprintf('%08d', $port); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $group2= sprintf('%04d-%04d-%04d-%012d', 0,0,0,0); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($server_id < 10) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $group2 =~ s/\d/$server_id/g; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | ▶ | elsif (($server_id >= 100) && ($server_id < 109)) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$server_id >= 100 and $server_id < 109
MC/DC0%0/2
$server_id >= 100 and $server_id < 109
$server_id >= 100
$server_id < 109
Truth table0%0/3
A and B
A= $server_id >= 100B= $server_id < 109
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $server_id -= 100; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | $server_id += 1 if $increase_id; # 101 => 2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $group2 =~ s/\d/$server_id/g; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | else | ||||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $second_id = $server_id; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ($second_id > 9999) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $second_id = 9999; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $group2 = sprintf( '%04d-%04d-%04d-%012d', $second_id, $second_id, $second_id, $server_id ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $new_uuid= "$group1-$group2"; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | open my $FH, '>', 'auto.cnf' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | or die "Error updating 'auto.cnf' ($!)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | print $FH "[auto]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | print $FH "server-uuid=$new_uuid\n"; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | close $FH; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | chdir $current_dir; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | print "New UUID=$new_uuid\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub validate_json_object { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_json_object: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my ($json_filename, $json_text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $JSON_module = undef; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | for my $module ( 'JSON', 'JSON::PP', 'JSON::XS') | |||||||||||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | eval "use $module;"; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if (! $@) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | print "# Using $module\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $JSON_module=$module; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | unless ($JSON_module) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | print "# JSON modules not installed - skipped evaluation\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | unless ($json_text) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $json_text = slurp($json_filename); | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $json = $JSON_module->new->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $perl_value; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $perl_value = $json->decode( $json_text ); | |||||||||||||||||||||||||||||||||||||||||
| 400 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ($@) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | { | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | print "error decoding json object\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return ; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | sub slurp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slurp: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my ($filename, $skip_blanks, $skip_comments ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | open my $FH , q{<}, $filename | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | or die "file '$filename' not found\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my @text_array = (); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $text=''; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | while (my $line = <$FH>) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | { | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | if ($skip_blanks) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | next if $line =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if ($skip_comments) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | next if $line =~ /^\s*#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | if (wantarray) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | push @text_array, $line; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | else | ||||||||||||||||||||||||||||||||||||||||||
| 430 | { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $text .= $line; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | close $FH; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if (wantarray) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | { | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | return @text_array; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | else | ||||||||||||||||||||||||||||||||||||||||||
| 440 | { | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub get_json_from_dirs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_json_from_dirs: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my ($directories, $json_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $collective_json = ''; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $indent = ' '; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | for my $dir (@$directories) | |||||||||||||||||||||||||||||||||||||||||
| 450 | { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $filename = "$dir/$json_file"; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if ($collective_json) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | { | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $collective_json .= ",\n" | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | else | ||||||||||||||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $collective_json = "{\n"; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $collective_json .= qq("$dir": \n); | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if ( -f $filename) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # get the contents | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my @json_lines = slurp($filename, 'skip_blanks'); | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | for my $jl (@json_lines) | |||||||||||||||||||||||||||||||||||||||||
| 466 | { | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $collective_json .= $indent . $jl; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | else | ||||||||||||||||||||||||||||||||||||||||||
| 471 | { | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | if ($DEBUG) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | { | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | warn "# No connection.json found in $dir\n"; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my ($package, $filename, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | warn "# called from $package - $filename - $line \n"; | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $collective_json .= "{}"; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $collective_json .= "}"; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my $is_valid_json = validate_json_object(undef, $collective_json); | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if ($is_valid_json && ($is_valid_json == -1)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$is_valid_json and $is_valid_json == -1
MC/DC0%0/2
$is_valid_json and $is_valid_json == -1
$is_valid_json
$is_valid_json == -1
Truth table0%0/3
A and B
A= $is_valid_jsonB= $is_valid_json == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ($DEBUG) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | { | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | warn "# Could not validate JSON object\n"; | |||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | elsif ( ! $is_valid_json) | ||||||||||||||||||||||||||||||||||||||||||
| 491 | { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | warn "Invalid JSON object in $ENV{PWD} from [@$directories] \n"; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $collective_json = qq({ "comment": "WARNING: invalid JSON object", "original" : ) | |||||||||||||||||||||||||||||||||||||||||
| 494 | . $collective_json | ||||||||||||||||||||||||||||||||||||||||||
| 495 | . "\n}"; | ||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return $collective_json; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | #sub get_version { | ||||||||||||||||||||||||||||||||||||||||||
| 501 | # my ($install_dir) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 502 | # open my $VER , q{<}, "$install_dir/VERSION" | ||||||||||||||||||||||||||||||||||||||||||
| 503 | # #open my $VER , q{<}, "VERSION" | ||||||||||||||||||||||||||||||||||||||||||
| 504 | # or die "file 'VERSION' not found\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | # my $version = <$VER>; | ||||||||||||||||||||||||||||||||||||||||||
| 506 | # chomp $version; | ||||||||||||||||||||||||||||||||||||||||||
| 507 | # close $VER; | ||||||||||||||||||||||||||||||||||||||||||
| 508 | # return $version; | ||||||||||||||||||||||||||||||||||||||||||
| 509 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | sub write_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_to: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my ($self, $fname, $mode, $contents) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | open my $FILE, $mode, $fname | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | or die "can't open file $fname\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | print $FILE $contents, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | if (($mode eq '>') && ( $contents =~ m/\#!\/bin\/sh/ ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mode eq ">" and $contents =~ m[\#!/bin/sh]
MC/DC0%0/2
$mode eq ">" and $contents =~ m[\#!/bin/sh]
$mode eq ">"
$contents =~ m[\#!/bin/sh]
Truth table0%0/3
A and B
A= $mode eq ">"B= $contents =~ m[\#!/bin/sh]
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | print $FILE $SBINSTR_SH_TEXT; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | close $FILE; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | sub supported_versions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_versions: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | return \@supported_versions; | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | sub is_port_open { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_port_open: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my ($port) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | die "No port" unless $port; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my ($host, $iaddr, $paddr, $proto); | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $host = '127.0.0.1'; | |||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | $iaddr = inet_aton($host) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | or die "no host: $host"; | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | $paddr = sockaddr_in($port, $iaddr); | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $proto = getprotobyname('tcp'); | |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | socket(SOCK, PF_INET, SOCK_STREAM, $proto) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | or die "error creating test socket for port $port: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | if (connect(SOCK, $paddr)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | close (SOCK) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | or die "error closing test socket: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | sub first_unused_port { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_unused_port: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | my ($port) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | while (is_port_open($port)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | $port++; | |||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if ($port > 0xFFF0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | die "no ports available\n"; | |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return $port; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 559 | # SBtool | ||||||||||||||||||||||||||||||||||||||||||
| 560 | # | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | sub get_sandbox_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_sandbox_params: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | my ($dir, $skip_strict) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | confess "directory name required\n" unless $dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | confess "directory $dir doesn't exist\n" unless -d $dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | unless (is_a_sandbox($dir)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | confess "directory <$dir> must be a sandbox\n" unless $skip_strict; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my %params = ( | |||||||||||||||||||||||||||||||||||||||||
| 569 | opt => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 570 | conf => undef | ||||||||||||||||||||||||||||||||||||||||||
| 571 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | if ( -f "$dir/$sandbox_options_file" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $params{opt} = get_option_file_contents("$dir/$sandbox_options_file"); | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 576 | # warn "options file $dir not found\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | # if ( -f "$dir/$sandbox_current_options" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 580 | # $params{conf} = | ||||||||||||||||||||||||||||||||||||||||||
| 581 | # get_option_file_contents("$dir/$sandbox_current_options"); | ||||||||||||||||||||||||||||||||||||||||||
| 582 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | # else { | ||||||||||||||||||||||||||||||||||||||||||
| 584 | # # warn "current conf file not found\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 585 | # return; | ||||||||||||||||||||||||||||||||||||||||||
| 586 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return \%params; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | sub get_option_file_contents { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_option_file_contents: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | confess "file name required\n" unless $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | confess "file $file doesn't exist\n" unless -f $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my %options; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | open my $RFILE, q{<}, $file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | or confess "can't open file $file\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | while ( my $line = <$RFILE> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | next if $line =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | next if $line =~ /^\s*#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | next if $line =~ /^\s*\[/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my ( $key, $val ) = split /\s*=\s*/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $key =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | $options{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | close $RFILE; | |||||||||||||||||||||||||||||||||||||||||
| 607 | # print Dumper(\%options) ; exit; | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | return \%options; | |||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | sub get_sb_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_sb_info: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my ($search_path, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | my %ports = (); | |||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | my %all_info = (); | |||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my $seen_dir = ''; | |||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | find( | ||||||||||||||||||||||||||||||||||||||||||
| 618 | { | ||||||||||||||||||||||||||||||||||||||||||
| 619 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 620 | follow => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | if ( $seen_dir eq $File::Find::dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | my $params; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | if ( $params = get_sandbox_params($File::Find::dir, 1) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | $seen_dir = $File::Find::dir; | |||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | my $port = $params->{opt}{port}; | |||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | if ( -f $params->{opt}{pid_file} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $params->{"opt"}{"pid_file"} and -e $params->{"opt"}{"socket"}
MC/DC0%0/2
-f $params->{"opt"}{"pid_file"} and -e $params->{"opt"}{"socket"}
-f $params->{"opt"}{"pid_file"}
-e $params->{"opt"}{"socket"}
Truth table0%0/3
A and B
A= -f $params->{"opt"}{"pid_file"}B= -e $params->{"opt"}{"socket"}
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | && -e $params->{opt}{socket} ) | ||||||||||||||||||||||||||||||||||||||||||
| 631 | { | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | $ports{$port} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | $all_info{$port} = $params if $options->{all_info}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | unless ( $options->{only_used} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | $ports{$port} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | $all_info{$port} = $params if $options->{all_info}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 644 | $search_path || $options->{search_path} | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$search_path || $options->{'search_path'}
MC/DC0%0/2
$search_path || $options->{'search_path'}
$search_path
$options->{'search_path'}
Truth table0%0/3
A || B
A= $search_pathB= $options->{'search_path'}
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | return ( \%ports, \%all_info ); | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | sub is_a_sandbox { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_a_sandbox: not called CC=4 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | my ($dir) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | unless ($dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | confess "directory missing\n"; | |||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $dir =~ s{/$}{}; | |||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | my %sandbox_files = map {s{.*/}{}; $_, 1 } glob("$dir/*"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my @required = (qw(data start stop send_kill clear use restart), | |||||||||||||||||||||||||||||||||||||||||
| 657 | # $sandbox_current_options, | ||||||||||||||||||||||||||||||||||||||||||
| 658 | $sandbox_options_file ); | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | for my $req (@required) { | |||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | unless (exists $sandbox_files{$req}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | sub is_sandbox_running { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_sandbox_running: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | my ($sandbox) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | unless ( -d $sandbox ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | confess "Can't see if it's running. <$sandbox> is not a sandbox\n"; | |||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | my $sboptions = get_sandbox_params($sandbox); | |||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | ▶ | unless ($sboptions->{opt} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$sboptions->{"opt"} and $sboptions->{"opt"}{"pid_file"} and $sboptions->{"opt"}{"socket"}
$sboptions->{"opt"} and $sboptions->{"opt"}{"pid_file"}
MC/DC0%0/3
$sboptions->{"opt"} and $sboptions->{"opt"}{"pid_file"} and $sboptions->{"opt"}{"socket"}
$sboptions->{"opt"}
$sboptions->{"opt"}{"pid_file"}
$sboptions->{"opt"}{"socket"}
Truth table0%0/4
A and B and C
A= $sboptions->{"opt"}B= $sboptions->{"opt"}{"pid_file"}C= $sboptions->{"opt"}{"socket"}
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | && $sboptions->{opt}{'pid_file'} | ||||||||||||||||||||||||||||||||||||||||||
| 675 | && $sboptions->{opt}{'socket'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 676 | # print Dumper($sboptions); | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | confess "<$sandbox> is not a single sandbox\n"; | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | if ( ( -f $sboptions->{opt}{'pid_file'} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $sboptions->{"opt"}{"pid_file"} and -e $sboptions->{"opt"}{"socket"}
MC/DC0%0/2
-f $sboptions->{"opt"}{"pid_file"} and -e $sboptions->{"opt"}{"socket"}
-f $sboptions->{"opt"}{"pid_file"}
-e $sboptions->{"opt"}{"socket"}
Truth table0%0/3
A and B
A= -f $sboptions->{"opt"}{"pid_file"}B= -e $sboptions->{"opt"}{"socket"}
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | && ( -e $sboptions->{opt}{'socket'}) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | return (1, $sboptions); | |||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return (0, $sboptions); | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | sub get_ranges { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_ranges: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my ($options, $silent ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | my ( $ports, $all_info ) = get_sb_info(undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | my $minimum_port = $options->{min_range}; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | my $maximum_port = $options->{max_range}; | |||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | my $range_size = $options->{range_size}; | |||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | ▶ | if ( $minimum_port >= $maximum_port ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | croak "minimum range must be lower than the maximum range\n"; | |||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | if ( ( $minimum_port + $range_size ) > $maximum_port ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | croak "range too wide for given boundaries\n"; | |||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my $range_found = 0; | |||||||||||||||||||||||||||||||||||||||||
| 701 | range_search: | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | while ( !$range_found ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | if ( $minimum_port >= $maximum_port ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | croak "can't find a range of $range_size " | |||||||||||||||||||||||||||||||||||||||||
| 705 | . "free ports between " | ||||||||||||||||||||||||||||||||||||||||||
| 706 | . "$options->{min_range} and $options->{max_range}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | for my $i ( $minimum_port .. $minimum_port + $range_size ) { | |||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | ▶ | if ( exists $ports->{$i} or ( $i >= $maximum_port ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ports->{$i} or $i >= $maximum_port
MC/DC0%0/2
exists $ports->{$i} or $i >= $maximum_port
exists $ports->{$i}
$i >= $maximum_port
Truth table0%0/3
A or B
A= exists $ports->{$i}B= $i >= $maximum_port
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $minimum_port = $i + 1; | |||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | next range_search; | |||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | $range_found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | unless ($silent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | printf "%5d - %5d\n", $minimum_port , $minimum_port + $range_size; | |||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | return $minimum_port; | |||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | sub get_ports { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_ports: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my ($options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | my ( $ports, $all_info ) = get_sb_info(undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | ▶ | if ( $options->{format} eq 'perl' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | print Data::Dumper->Dump( [$ports], ['ports'] ); | |||||||||||||||||||||||||||||||||||||||||
| 728 | print Data::Dumper->Dump( [$all_info], ['all_info'] ) | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | if $options->{all_info}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | elsif ( $options->{format} eq 'text' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | for my $port ( sort { $a <=> $b } keys %$ports ) { | |||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | printf "%5d %2d\n", $port, $ports->{$port}; | |||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | croak "unrecognized format -> $options->{format}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | return ( $ports, $all_info ); | |||||||||||||||||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | sub exists_in_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists_in_path: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | my ($cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my @path_directories = split /:/, $ENV{PATH}; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | for my $dir (@path_directories) { | |||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | if ( -x "$dir/$cmd") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | return "$dir/$cmd"; | |||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | return ; | |||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | sub runs_as_root { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
runs_as_root: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | ▶ | if ( ($REAL_USER_ID == 0) or ($EFFECTIVE_USER_ID == 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$MySQL::Sandbox::REAL_USER_ID == 0 or $MySQL::Sandbox::EFFECTIVE_USER_ID == 0
MC/DC0%0/2
$MySQL::Sandbox::REAL_USER_ID == 0 or $MySQL::Sandbox::EFFECTIVE_USER_ID == 0
$MySQL::Sandbox::REAL_USER_ID == 0
$MySQL::Sandbox::EFFECTIVE_USER_ID == 0
Truth table0%0/3
A or B
A= $MySQL::Sandbox::REAL_USER_ID == 0B= $MySQL::Sandbox::EFFECTIVE_USER_ID == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | unless ($ENV{SANDBOX_AS_ROOT}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | die "MySQL Sandbox should not run as root\n" | |||||||||||||||||||||||||||||||||||||||||
| 757 | . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 758 | . "If you know what you are doing and want to\n " | ||||||||||||||||||||||||||||||||||||||||||
| 759 | . "run as root nonetheless, please set the environment\n" | ||||||||||||||||||||||||||||||||||||||||||
| 760 | . "variable 'SANDBOX_AS_ROOT' to a nonzero value\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | sub mylogin_cnf_exists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mylogin_cnf_exists: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | my $mylogin_cnf = "$ENV{HOME}/.mylogin.cnf"; | |||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | if ( -r $mylogin_cnf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | unless ($ENV{IGNORE_MYLOGIN_CNF}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | die "MySQL Sandbox does not work with \$HOME/.mylogin.cnf,\n" | |||||||||||||||||||||||||||||||||||||||||
| 770 | . "which is a file created by mysql_config_editor.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 771 | . "Either remove the file or make it not readable by the current user.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 772 | . "If you know what you are doing, you can skip this check by\n" | ||||||||||||||||||||||||||||||||||||||||||
| 773 | . "setting the variable IGNORE_MYLOGIN_CNF to a nonzero value.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 774 | . "Be aware that having \$HOME/.mylogin.cnf can disrupt MySQL-Sandbox.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 775 | . "Use it at your own risk.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | # | ||||||||||||||||||||||||||||||||||||||||||
| 781 | # Replaces a path portion with an environment variable name | ||||||||||||||||||||||||||||||||||||||||||
| 782 | # if a match is found | ||||||||||||||||||||||||||||||||||||||||||
| 783 | # | ||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | sub use_env{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
use_env: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | my @vars = ( | |||||||||||||||||||||||||||||||||||||||||
| 787 | 'HOME', | ||||||||||||||||||||||||||||||||||||||||||
| 788 | 'SANDBOX_HOME', | ||||||||||||||||||||||||||||||||||||||||||
| 789 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | return '' unless $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | for my $var (@vars) { | |||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | if ($path =~ /^$ENV{$var}/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | $path =~ s/$ENV{$var}/\$$var/; | |||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | ▶ | sub sbinstr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sbinstr: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | unless ($ENV{SBINSTR}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my $pname = $PROGRAM_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | ▶ | unless ($DEBUG) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | $pname =~ s{.*/}{}; | |||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | open my $FH, '>>', $ENV{SBINSTR} | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | or die "can't write to $ENV{SBINSTR} ($!)\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); | |||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | $mon++; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | $year +=1900; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | print $FH "[$pname] - ", | |||||||||||||||||||||||||||||||||||||||||
| 815 | sprintf('%4d-%02d%02d %02d:%02d:%02d', | ||||||||||||||||||||||||||||||||||||||||||
| 816 | $year, $mon, $mday, $hour, $min, $sec), | ||||||||||||||||||||||||||||||||||||||||||
| 817 | " - $msg \n"; | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | close $FH; | |||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 822 | __END__ | ||||||||||||||||||||||||||||||||||||||||||