brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.32k stars 620 forks source link

Fix AC/battery detection logic on FreeBSD. #1972

Closed fernape closed 5 months ago

fernape commented 5 months ago

The logic for the detection of the battery/AC line was not completely correct for FreeBSD. Launching conky on console shows the following:

Cannot read sysctl "hw.acpi.battery.time" Cannot read sysctl "hw.acpi.battery.life" Cannot read sysctl "hw.acpi.battery.state" Cannot read sysctl "hw.acpi.acline" Unknown battery state 8!

In a PC, the hw.acpi.battery MIB does not exist. Also, the hw.acpi.acline is only present if supported by the hardware. In addition, some variables were used uninitialized and that causes strange behavior: in a PC it showed it worked on battery and the % of charge was an ridiculous big number.

bad

This patch addresses the issue. It fixes the problem in the PC. It has also being tested in a laptop running FreeBSD current plugin and unplugging the AC line and also snatching the battery mercilessly to see if something breaks.

good

Checklist

Description

netlify[bot] commented 5 months ago

Deploy Preview for conkyweb canceled.

Name Link
Latest commit f1f9c41cd527e798b7b6574f8a290114d7f9bd7a
Latest deploy log https://app.netlify.com/sites/conkyweb/deploys/666c7ffd921e8d00088f9e7f
fernape commented 5 months ago

Overall it's good, but since you're making changes here we should replace those fprintf() calls with NORM_ERR instead, if you wouldn't mind.

Thank you for the suggestion. I didn't know about NORM_ERROR and the fprintf() were already there. I'll take that into account.