summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolashennion@gmail.com>2024-06-15 08:42:32 +0200
committernicolargo <nicolashennion@gmail.com>2024-06-15 08:42:32 +0200
commit0227d221da5c69e6c244c77a2b81defb28170aaf (patch)
tree3d9759525615dfeda6f2915e55edc9a16baec75b
parent3f395224877988d3d8d813c0605ae837d52f15a2 (diff)
[snap] PermissionError: [Errno 13] Permission denied: '/proc/net/wireless' #2829
-rw-r--r--glances/plugins/wifi/__init__.py58
-rw-r--r--snap/snapcraft.yaml3
2 files changed, 34 insertions, 27 deletions
diff --git a/glances/plugins/wifi/__init__.py b/glances/plugins/wifi/__init__.py
index dc6fc5a1..0781c978 100644
--- a/glances/plugins/wifi/__init__.py
+++ b/glances/plugins/wifi/__init__.py
@@ -22,13 +22,13 @@ from glances.globals import file_exists, nativestr
from glances.logger import logger
from glances.plugins.plugin.model import GlancesPluginModel
-# Backup solution is to use the /proc/net/wireless file
-# but it only give signal information about the current hotspot
+# Use stats available in the /proc/net/wireless file
+# Note: it only give signal information about the current hotspot
WIRELESS_FILE = '/proc/net/wireless'
wireless_file_exists = file_exists(WIRELESS_FILE)
if not wireless_file_exists:
- logger.debug(f"Wifi plugin is disabled (no {WIRELESS_FILE} file found)")
+ logger.debug(f"Wifi plugin is disabled (can not read {WIRELESS_FILE} file)")
# Fields description
# description: human readable description
@@ -96,31 +96,12 @@ class PluginModel(GlancesPluginModel):
return stats
if self.input_method == 'local' and wireless_file_exists:
- # As a backup solution, use the /proc/net/wireless file
- with open(WIRELESS_FILE) as f:
- # The first two lines are header
- f.readline()
- f.readline()
- # Others lines are Wifi stats
- wifi_stats = f.readline()
- while wifi_stats != '':
- # Extract the stats
- wifi_stats = wifi_stats.split()
- # Add the Wifi link to the list
- stats.append(
- {
- 'key': self.get_key(),
- 'ssid': wifi_stats[0][:-1],
- 'quality_link': float(wifi_stats[2]),
- 'quality_level': float(wifi_stats[3]),
- }
- )
- # Next line
- wifi_stats = f.readline()
-
+ try:
+ stats = self._get_wireless_stats()
+ except (PermissionError, FileNotFoundError) as e:
+ logger.debug(f"Wifi plugin error: can not read {WIRELESS_FILE} file ({e})")
elif self.input_method == 'snmp':
# Update stats using SNMP
-
# Not implemented yet
pass
@@ -129,6 +110,31 @@ class PluginModel(GlancesPluginModel):
return self.stats
+ def _get_wireless_stats(self):
+ ret = self.get_init_value()
+ # As a backup solution, use the /proc/net/wireless file
+ with open(WIRELESS_FILE) as f:
+ # The first two lines are header
+ f.readline()
+ f.readline()
+ # Others lines are Wifi stats
+ wifi_stats = f.readline()
+ while wifi_stats != '':
+ # Extract the stats
+ wifi_stats = wifi_stats.split()
+ # Add the Wifi link to the list
+ ret.append(
+ {
+ 'key': self.get_key(),
+ 'ssid': wifi_stats[0][:-1],
+ 'quality_link': float(wifi_stats[2]),
+ 'quality_level': float(wifi_stats[3]),
+ }
+ )
+ # Next line
+ wifi_stats = f.readline()
+ return ret
+
def get_alert(self, value):
"""Overwrite the default get_alert method.
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index 0a0f9db3..041a1ab2 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -1,5 +1,5 @@
name: glances
-version: '4.0.8'
+version: '4.0.8+build2'
summary: Glances an Eye on your system. A top/htop alternative.
description: |
@@ -31,6 +31,7 @@ apps:
- removable-media
- power-control
- process-control
+ - network-setup-observe
environment:
LANG: C.UTF-8
LC_ALL: C.UTF-8