@@ -56,14 +56,32 @@ def _paths_from_args(args: Optional[SysSettingsCollectorArgs]) -> list[str]:
5656 """Extract list of sysfs paths from collection args.
5757
5858 Args:
59- args: Collector args containing paths to read, or None.
59+ args: Collector args containing paths to read, or None. May be a dict.
6060
6161 Returns:
6262 List of sysfs paths; empty if args is None or args.paths is empty.
6363 """
6464 if args is None :
6565 return []
66- return list (args .paths ) if args .paths else []
66+ paths = args .get ("paths" ) if isinstance (args , dict ) else getattr (args , "paths" , None )
67+ return list (paths ) if paths else []
68+
69+
70+ def _path_under_sys (path : str ) -> Optional [str ]:
71+ """Normalize path to the suffix under /sys/ for use in 'cat /sys/{}'."""
72+ if ".." in path :
73+ return None
74+ p = path .strip ().lstrip ("/" )
75+ if p .startswith ("sys/" ):
76+ p = p [4 :]
77+ if p .startswith ("/" ):
78+ return None
79+ return p if p else None
80+
81+
82+ def _sysfs_full_path (suffix : str ) -> str :
83+ """Return full path /sys/{suffix}."""
84+ return f"/sys/{ suffix } "
6785
6886
6987class SysSettingsCollector (InBandDataCollector [SysSettingsDataModel , SysSettingsCollectorArgs ]):
@@ -72,7 +90,7 @@ class SysSettingsCollector(InBandDataCollector[SysSettingsDataModel, SysSettings
7290 DATA_MODEL = SysSettingsDataModel
7391 SUPPORTED_OS_FAMILY : set [OSFamily ] = {OSFamily .LINUX }
7492
75- CMD = "cat {}"
93+ CMD = "cat /sys/ {}"
7694
7795 def collect_data (
7896 self , args : Optional [SysSettingsCollectorArgs ] = None
@@ -102,14 +120,25 @@ def collect_data(
102120
103121 readings : dict [str , str ] = {}
104122 for path in paths :
105- res = self ._run_sut_cmd (self .CMD .format (path ), sudo = False )
123+ suffix = _path_under_sys (path )
124+ if suffix is None :
125+ self ._log_event (
126+ category = EventCategory .OS ,
127+ description = f"Skipping path not under /sys or invalid: { path !r} " ,
128+ data = {"path" : path },
129+ priority = EventPriority .WARNING ,
130+ console_log = True ,
131+ )
132+ continue
133+ full_path = _sysfs_full_path (suffix )
134+ res = self ._run_sut_cmd (self .CMD .format (suffix ), sudo = False )
106135 if res .exit_code == 0 and res .stdout :
107136 value = _parse_bracketed_setting (res .stdout ) or res .stdout .strip ()
108- readings [path ] = value
137+ readings [full_path ] = value
109138 else :
110139 self ._log_event (
111140 category = EventCategory .OS ,
112- description = f"Failed to read sysfs path: { path } " ,
141+ description = f"Failed to read sysfs path: { full_path } " ,
113142 data = {"exit_code" : res .exit_code },
114143 priority = EventPriority .WARNING ,
115144 console_log = True ,
0 commit comments