From: Galen Charlton Date: Fri, 18 Aug 2017 15:11:29 +0000 (-0400) Subject: LP#1711194: avoid division by zero errors X-Git-Tag: osrf_rel_3_0_0-alpha~13 X-Git-Url: http://git.equinoxoli.org/?p=opensrf-equinox.git;a=commitdiff_plain;h=53e7f82b534eef2b513fe31bcb2a9c719a7ee746 LP#1711194: avoid division by zero errors Under some circumstances, osrf_control --diagnostic may not be able to deduce the correct max_children setting for a service, e.g., if it's run without --localhost on a system that doesn't have a opensrf.xml config section specifying active apps for a specific hostname. When that happens, just display the count of running drones rather than displaying error messages about undefined $dmax values and divisions by zero. Signed-off-by: Galen Charlton Signed-off-by: Bill Erickson --- diff --git a/bin/opensrf-perl.pl.in b/bin/opensrf-perl.pl.in index 021f00e..40015e3 100755 --- a/bin/opensrf-perl.pl.in +++ b/bin/opensrf-perl.pl.in @@ -267,8 +267,12 @@ sub do_diagnostic { my @drones = `pgrep -f "Drone \\[$svc\\]"`; my $dcount = scalar(@drones); my $dmax = $max_children_map{$svc}; - $str .= "#drones=$dcount/$dmax "; - $str .= sprintf('%3d%%', (int(($dcount / $dmax) * 100))); + if (defined($dmax) && $dmax > 0) { + $str .= "#drones=$dcount/$dmax "; + $str .= sprintf('%3d%%', (int(($dcount / $dmax) * 100))); + } else { + $str .= "#drones=$dcount"; + } msg($str); msg("\tERR $svc has no running drones.") unless @drones; }