From: Leo-Andres Hofmann Date: Fri, 23 Jul 2021 11:09:42 +0000 (+0200) Subject: network-functions.pl: Improve wifi_get_link_quality X-Git-Tag: v2.27-core160~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dd084c22d05271c205a3bacf86da7689e4e3dbb;p=ipfire-2.x.git network-functions.pl: Improve wifi_get_link_quality iwconfig doesn't return values for "Link Quality" if the interface is disconnected, causing a division by zero error. If there are odd values, the resulting percentage may contain many decimal places. This patch makes wifi_get_link_quality return zero instead of failing and rounds the percentage to a more meaningful integer. Signed-off-by: Leo-Andres Hofmann Reviewed-by: Michael Tremer Signed-off-by: Arne Fitzenreiter --- diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index b7a840559c..c0abc76b52 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -403,7 +403,11 @@ sub wifi_get_link_quality($) { my ($cur, $max) = $status =~ /Link Quality=(\d+)\/(\d+)/; - return $cur * 100 / $max; + if($max > 0) { + return sprintf('%.0f', ($cur * 100) / $max); + } + + return 0; } sub wifi_get_signal_level($) {