fix(tools): use integer check from validate module in manage vnc pipe

main^2
Tsu-ba-me 7 months ago
parent a1f429201d
commit 1a0e3612dc
  1. 16
      tools/anvil-manage-vnc-pipe

@ -99,8 +99,7 @@ sub build_find_available_port_call
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters, prefix => "build_find_available_port_call" }); $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters, prefix => "build_find_available_port_call" });
return (1) if ( (not $step_operator =~ /^[+-]$/) return (1) if ( (not $step_operator =~ /^[+-]$/) || (not $anvil->Validate->positive_integer({ number => $step_size })) );
|| (not is_int($step_size)) || ($step_size < 1) );
my $call = "ss_output=\$($ss -ant) && port=${start} && while $grep -Eq \":\${port}[[:space:]]+[^[:space:]]+\" <<<\$ss_output; do (( port ${step_operator}= $step_size )); done && $echo \$port"; my $call = "ss_output=\$($ss -ant) && port=${start} && while $grep -Eq \":\${port}[[:space:]]+[^[:space:]]+\" <<<\$ss_output; do (( port ${step_operator}= $step_size )); done && $echo \$port";
@ -203,7 +202,7 @@ sub find_server_vnc_port
return (1) if (not defined $svr_uuid); return (1) if (not defined $svr_uuid);
return (0, $svr_vnc_port) if (is_int($svr_vnc_port)); return (0, $svr_vnc_port) if ($anvil->Validate->positive_integer({ number => $svr_vnc_port }));
# If we don't have the server's VNC port, find it in its qemu-kvm process. # If we don't have the server's VNC port, find it in its qemu-kvm process.
@ -253,11 +252,6 @@ sub find_ws_processes
return (0, $result); return (0, $result);
} }
sub is_int
{
return defined $_[0] && $_[0] =~ /^\d+$/;
}
sub prettify sub prettify
{ {
my $var_value = shift; my $var_value = shift;
@ -411,8 +405,8 @@ sub start_ws
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters, prefix => "start_ws" }); $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters, prefix => "start_ws" });
return (1) if ( (not defined $ws_processes) return (1) if ( (not defined $ws_processes)
|| (not is_int($svr_vnc_port)) || (not $anvil->Validate->positive_integer({ number => $svr_vnc_port }))
|| (not is_int($ws_sport_offset)) ); || (not $anvil->Validate->positive_integer({ number => $ws_sport_offset })) );
my $existing_ws_pids = $ws_processes->{targets}{$svr_vnc_port}; my $existing_ws_pids = $ws_processes->{targets}{$svr_vnc_port};
@ -506,7 +500,7 @@ sub stop_ws
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters, prefix => "stop_ws" }); $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => $parameters, prefix => "stop_ws" });
return (1) if ( (not is_int($ws_pid)) || (not defined $ws_processes) ); return (1) if ( (not $anvil->Validate->positive_integer({ number => $ws_pid })) || (not defined $ws_processes) );
call({ debug => $debug, call => "$kill $ws_pid || $kill -9 $ws_pid" }); call({ debug => $debug, call => "$kill $ws_pid || $kill -9 $ws_pid" });

Loading…
Cancel
Save