Add missing timeouts to all subprocess calls
Add timeout=30 to smartctl -i calls in _get_drive_details() and _check_disk_firmware(), and dmidecode in _check_memory_usage(). Add TimeoutExpired handler in _check_disk_firmware(). Prevents potential hangs when drives or system tools become unresponsive. Resolves #9 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1051,7 +1051,8 @@ class SystemHealthMonitor:
|
||||
['smartctl', '-i', device],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
# Check if smartctl failed completely
|
||||
@@ -2065,9 +2066,10 @@ class SystemHealthMonitor:
|
||||
['smartctl', '-i', device],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
|
||||
model_line = None
|
||||
for line in result.stdout.split('\n'):
|
||||
if 'Firmware Version:' in line:
|
||||
@@ -2105,9 +2107,11 @@ class SystemHealthMonitor:
|
||||
logger.debug(f"Known issues: {firmware_info['known_issues']}")
|
||||
logger.debug("=== End Firmware Check ===\n")
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
logger.warning(f"smartctl -i timed out for {device}")
|
||||
except Exception as e:
|
||||
firmware_info['known_issues'].append(f"Error checking firmware: {str(e)}")
|
||||
|
||||
|
||||
return firmware_info
|
||||
|
||||
# =============================================================================
|
||||
@@ -2813,7 +2817,8 @@ class SystemHealthMonitor:
|
||||
['dmidecode', '--type', 'memory'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
if 'Error Correction Type: Multi-bit ECC' in result.stdout:
|
||||
memory_health['has_ecc'] = True
|
||||
|
||||
Reference in New Issue
Block a user