Skip to content

Commit abcc3e0

Browse files
committed
Check attributes under /sys can be read without stucking the system
1 parent 38b29e2 commit abcc3e0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/env python3
2+
import os
3+
import multiprocessing
4+
import sys
5+
6+
7+
def try_read_node(path):
8+
"""
9+
Attempts to read a single sysfs attribute.
10+
Isolated in a subprocess to protect against D-state hangs.
11+
"""
12+
try:
13+
with open(path, "r") as f:
14+
# We only need the first byte to trigger the kernel 'show' function
15+
f.read(1)
16+
except Exception:
17+
pass
18+
19+
20+
def walk_devices(base_path="/sys/devices", timeout=10.0):
21+
22+
# We use os.walk but skip non-device directories if necessary
23+
failed = 0
24+
for root, dirs, files in os.walk(base_path):
25+
for name in files:
26+
full_path = os.path.join(root, name)
27+
28+
# Skip known 'noisy' or non-hardware files to be efficient
29+
if name in ["uevent", "modalias", "resource"]:
30+
continue
31+
32+
if os.access(full_path, os.R_OK):
33+
p = multiprocessing.Process(
34+
target=try_read_node, args=(full_path,)
35+
)
36+
p.start()
37+
38+
p.join(timeout)
39+
40+
if p.is_alive():
41+
failed = 1
42+
print(f"{full_path}")
43+
p.terminate()
44+
p.join()
45+
# We stay silent on success to highlight the problem areas
46+
return failed
47+
48+
49+
if __name__ == "__main__":
50+
print(
51+
"Scanning /sys/devices for unresponsive attributes (Timeout: 10s)..."
52+
)
53+
sys.exit(walk_devices())

providers/base/units/miscellanea/jobs.pxu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,10 @@ _steps:
632632
3. Boot into the recovered system without errors
633633
_verification:
634634
1. The system boots into the factory recovery system successfully.
635+
636+
plugin: shell
637+
category_id: com.canonical.plainbox::miscellanea
638+
estimated_duration: 120.0
639+
id: miscellanea/check-hardware-attributes
640+
command: check_hardware_attributes.py
641+
_summary: Check that all the attributes are able to read

0 commit comments

Comments
 (0)