[snap] PermissionError: [Errno 13] Permission denied: '/proc/net/wireless' #2829

This commit is contained in:
nicolargo 2024-06-15 08:42:32 +02:00
parent 3f39522487
commit 0227d221da
2 changed files with 34 additions and 27 deletions

View File

@ -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,6 +96,22 @@ class PluginModel(GlancesPluginModel):
return stats
if self.input_method == 'local' and wireless_file_exists:
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
# Update the stats
self.stats = stats
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
@ -107,7 +123,7 @@ class PluginModel(GlancesPluginModel):
# Extract the stats
wifi_stats = wifi_stats.split()
# Add the Wifi link to the list
stats.append(
ret.append(
{
'key': self.get_key(),
'ssid': wifi_stats[0][:-1],
@ -117,17 +133,7 @@ class PluginModel(GlancesPluginModel):
)
# Next line
wifi_stats = f.readline()
elif self.input_method == 'snmp':
# Update stats using SNMP
# Not implemented yet
pass
# Update the stats
self.stats = stats
return self.stats
return ret
def get_alert(self, value):
"""Overwrite the default get_alert method.

View File

@ -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