fix hwmon nil ptr (#2873)

* fix hwmon nil ptr

syslink maybe lost in some cases.

---------

Signed-off-by: TaoGe <6657718+yowenter@users.noreply.github.com>
This commit is contained in:
TaoGe 2024-02-03 17:13:12 +08:00 committed by GitHub
parent 14949db87f
commit fe78e7e51a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -446,7 +446,10 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
for _, hwDir := range hwmonFiles {
hwmonXPathName := filepath.Join(hwmonPathName, hwDir.Name())
fileInfo, _ := os.Lstat(hwmonXPathName)
fileInfo, err := os.Lstat(hwmonXPathName)
if err != nil {
continue
}
if fileInfo.Mode()&os.ModeSymlink > 0 {
fileInfo, err = os.Stat(hwmonXPathName)