diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php index 23a7dee..602c7c2 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php @@ -79,7 +79,8 @@ function build_pwm_map(): array { $chip = normalize_chip_name(trim(file_get_contents($name_file))); - foreach (glob("$dir/pwm[0-9]") as $pwm_path) { + foreach (glob("$dir/pwm*") as $pwm_path) { + if (!preg_match('/^pwm\d+$/', basename($pwm_path))) continue; $pwmN = basename($pwm_path); $real = realpath($pwm_path) ?: $pwm_path; $map["$chip:$pwmN"] = $real; @@ -234,15 +235,23 @@ function migrate_cfg_and_labels(string $plugin): void { function list_pwm() { $out = []; - exec("find /sys/devices -type f -iname 'pwm[0-9]' -exec dirname \"{}\" + | uniq", $chips); - foreach ($chips as $chip) { + // Enumerate via /sys/class/hwmon, same as build_pwm_map() above -- avoids + // a shell exec() + GNU-only `find -regextype` (unavailable on some find + // implementations), and glob("pwm*") + a strict regex filter correctly + // excludes per-channel attributes (pwm1_enable, pwm1_auto_point1_pwm, + // etc.) that a bare "pwm[0-9]*" pattern would also match, since a glob + // char class only consumes one character before the trailing "*" takes + // over -- "pwm[0-9]*" still matches "pwm1_enable" the same way "pwm*" + // does. + foreach (glob('/sys/class/hwmon/hwmon*') as $chip) { $name = is_file("$chip/name") ? trim(file_get_contents("$chip/name")) : ''; - foreach (glob("$chip/pwm[0-9]") as $pwm) { + foreach (glob("$chip/pwm*") as $pwm) { + if (!preg_match('/^pwm\d+$/', basename($pwm))) continue; $out[] = ['chip' => $name, 'name' => basename($pwm), 'sensor' => $pwm]; } } - usort($out, fn($a, $b) => strcmp($a['name'], $b['name'])); + usort($out, fn($a, $b) => strnatcmp($a['name'], $b['name'])); return $out; }