fix openbsd battery: obtain statistics from sysctl, using OpenBSD's apm as fallback, and return an empty string on failure #1332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Hello everyone,
eww currently crashes when launched on OpenBSD, as the output from OpenBSD's apm tool isn't similar to the one from FreeBSD, which has a slightly different format from FreeBSD (NetBSD could potentially suffer from the same issue).
I've thus written an OpenBSD specific battery statistics handler, which simply obtains the information from the sysctl interface to acpibat (with acpisbs currently lacking an implementation).
Additionally, the OpenBSD specific handler will return a dummy JSON string, instead of crashing outright, if it can't launch one of the two programs.
Also, this is the first time I've written anything serious in Rust, and only the second time I've written Rust at all, so the code is almost certainly terrible.
Additional Notes
acpibat
from the regex, but since I don't have a system where the acpisbs driver would initialize I don't have a quick and easy way to confirm that they work the same way)Checklist
docs/content/main
directory has been adjusted to reflect my changes.cargo fmt
to automatically format all code before committing