public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH] network-functions.pl: Improve wifi_get_link_quality
@ 2021-07-23 11:09 Leo-Andres Hofmann
  2021-08-04 14:36 ` Michael Tremer
  0 siblings, 1 reply; 2+ messages in thread
From: Leo-Andres Hofmann @ 2021-07-23 11:09 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1013 bytes --]

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 <hofmann(a)leo-andres.de>
---
 config/cfgroot/network-functions.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl
index b7a840559..c0abc76b5 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($) {
-- 
2.27.0.windows.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-04 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 11:09 [PATCH] network-functions.pl: Improve wifi_get_link_quality Leo-Andres Hofmann
2021-08-04 14:36 ` Michael Tremer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox