Skip to content

Commit

Permalink
Remove redundant calls in get_dpinger_status()
Browse files Browse the repository at this point in the history
Don't call running_dpinger_processes() and get_gateways() in
get_dpinger_status() since it's already done in the calling function.

Also remove the error log for missing dpinger processes since
get_dpinger_status() is only called for existing dpinger processes.
  • Loading branch information
marcos-ng committed Dec 20, 2024
1 parent 7de19c3 commit a665634
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/etc/inc/gwlb.inc
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,20 @@ function remove_failover_states(?string $gateway_name = null): void {
}
}

function get_dpinger_status($gwname, $action_disable = false) {
$running_processes = running_dpinger_processes();

if (!isset($running_processes[$gwname])) {
log_error(sprintf(gettext(
'dpinger: No dpinger session running for gateway %s'),
$gwname));
function get_dpinger_status($gwitem, $proc) {
if (is_array($gwitem)) {
// The gateway config from get_gateways()
$gwname = $gwitem['name'];
$action_disable = isset($gwitem['action_disable']);
$gw = $gwitem;
} elseif (is_string($gwitem)) {
// The gateway no longer exists in the config
$gwname = $gwitem;
$action_disable = false;
} else {
return false;
}

$proc = $running_processes[$gwname];
unset($running_processes);

$timeoutcounter = 0;
while (true) {
if (!file_exists($proc['socket'])) {
Expand Down Expand Up @@ -687,13 +688,6 @@ function get_dpinger_status($gwname, $action_disable = false) {
$r['srcip'] = $proc['srcip'];
$r['targetip'] = $proc['targetip'];

$gateways_arr = get_gateways();

unset($gw);
if (isset($gateways_arr[$gwname])) {
$gw = $gateways_arr[$gwname];
}

$r['latency_avg'] = round($r['latency_avg']/1000, 3);
$r['latency_stddev'] = round($r['latency_stddev']/1000, 3);

Expand Down Expand Up @@ -753,8 +747,7 @@ function return_gateways_status($byname = false) {
* rather than just "down". Because reporting the gateway
* down would be misleading (gateway action is disabled)
*/
$action_disable = $gateways_arr[$gwname]['action_disable'];
$dpinger_status = get_dpinger_status($gwname, $action_disable);
$dpinger_status = get_dpinger_status(($gateways_arr[$gwname] ?? $gwname), $gwdata);
if ($dpinger_status === false) {
continue;
}
Expand Down

0 comments on commit a665634

Please sign in to comment.