Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/usr/local/emhttp/plugins/fanctrlplus2/include/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment thread
andrebrait marked this conversation as resolved.
if (!preg_match('/^pwm\d+$/', basename($pwm_path))) continue;
$pwmN = basename($pwm_path);
$real = realpath($pwm_path) ?: $pwm_path;
$map["$chip:$pwmN"] = $real;
Expand Down Expand Up @@ -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);
Comment thread
andrebrait marked this conversation as resolved.
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) {
Comment thread
andrebrait marked this conversation as resolved.
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']));
Comment thread
andrebrait marked this conversation as resolved.
return $out;
}

Expand Down