Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AC/battery detection logic on FreeBSD. #1972

Merged
merged 3 commits into from
Jun 15, 2024

Conversation

fernape
Copy link
Contributor

@fernape fernape commented Jun 13, 2024

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

  • I have described the changes
  • I have linked to any relevant GitHub issues, if applicable
  • [x ] Documentation in doc/ has been updated
  • All new code is licensed under GPLv3

Description

  • Describe the changes, why they were necessary, etc
  • Describe how the changes will affect existing behaviour.
  • Describe how you tested and validated your changes.
  • Include any relevant screenshots/evidence demonstrating that the changes work and have been tested.

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.

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.
@github-actions github-actions bot added the sources PR modifies project sources label Jun 13, 2024
Copy link

netlify bot commented Jun 13, 2024

Deploy Preview for conkyweb canceled.

Name Link
🔨 Latest commit f1f9c41
🔍 Latest deploy log https://app.netlify.com/sites/conkyweb/deploys/666c7ffd921e8d00088f9e7f

Copy link
Owner

@brndnmtthws brndnmtthws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

src/freebsd.cc Outdated

if (battery_present) {
if (battime && GETSYSCTL("hw.acpi.battery.time", *battime)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n");
NORM_ERR("Cannot read sysctl \"hw.acpi.battery.time\"");

src/freebsd.cc Outdated
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n");
}
if (batcapacity && GETSYSCTL("hw.acpi.battery.life", *batcapacity)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.life\"\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.life\"\n");
NORM_ERR("Cannot read sysctl \"hw.acpi.battery.life\"");

src/freebsd.cc Outdated
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.life\"\n");
}
if (batstate && GETSYSCTL("hw.acpi.battery.state", *batstate)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.state\"\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.state\"\n");
NORM_ERR("Cannot read sysctl \"hw.acpi.battery.state\"");

@fernape fernape requested a review from brndnmtthws June 14, 2024 17:51
@fernape
Copy link
Contributor Author

fernape commented Jun 14, 2024

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.

@brndnmtthws brndnmtthws merged commit 6cf51b2 into brndnmtthws:main Jun 15, 2024
40 checks passed
@brndnmtthws brndnmtthws added the bug Bug report or bug fix PR label Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report or bug fix PR sources PR modifies project sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants