Skip to content

CPU (Linux): fixes x86_pkg_temp and cputemp.* temperature detection - #2774

Merged
CarterLi merged 1 commit into
fastfetch-cli:devfrom
sagaragas:fix/linux-cpu-temp-detection
Dec 1, 2026
Merged

CarterLi merged 1 commit into
fastfetch-cli:devfrom
sagaragas:fix/linux-cpu-temp-detection

Conversation

@sagaragas

Copy link
Copy Markdown
Contributor

Fixes two cases in src/detection/cpu/cpu_linux.c where Linux CPU temperature detection always returns unset:

  • parseTZDir() reads /sys/class/thermal/thermal_zone*/type without trimming the trailing \n from sysfs, so ffStrbufEqualS(buffer, "x86_pkg_temp") never matches. Trimming trailing whitespace fixes it, matching parseHwmonDir().
  • detectCPUTemp() opens /sys/class/platform/ when tempSensor starts with cputemp., which doesn't exist in Linux sysfs. Opening /sys/devices/platform/ matches the auto-detection loop below it.

I verified both cases in an unshare --user --map-root-user --mount namespace with bind-mounted sysfs fixtures: an empty /sys/class/hwmon, thermal_zone0 (type = x86_pkg_temp\n, temp = 47500\n), and /sys/devices/platform/cputemp.0/temp1_input (51200\n). cpu-auto.json uses {"modules":[{"type":"cpu","temp":true}]} and cpu-cputemp.json adds "tempSensor":"cputemp.0".

# Before:
$ fastfetch -l none --pipe -c cpu-auto.json
CPU: AMD Ryzen 9 6900HX (16) @ 4.94 GHz
$ fastfetch -l none --pipe -c cpu-cputemp.json
CPU: AMD Ryzen 9 6900HX (16) @ 4.94 GHz

# After:
$ fastfetch -l none --pipe -c cpu-auto.json
CPU: AMD Ryzen 9 6900HX (16) @ 4.94 GHz - 47.5°C
$ fastfetch -l none --pipe -c cpu-cputemp.json
CPU: AMD Ryzen 9 6900HX (16) @ 4.94 GHz - 51.2°C

ctest passes (21/21).

`parseTZDir` reads `/sys/class/thermal/thermal_zone*/type` without
trimming the trailing newline sysfs appends, so
`ffStrbufEqualS(buffer, "x86_pkg_temp")` never matched. Trim trailing
whitespace like `parseHwmonDir` does.

`detectCPUTemp` also opened `/sys/class/platform/` when `tempSensor`
started with `cputemp.`, which does not exist in Linux sysfs. Open
`/sys/devices/platform/` to match the auto-detection loop below it.
@CarterLi
CarterLi merged commit 01ce701 into fastfetch-cli:dev Dec 1, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants