You are not logged in.

#1 Yesterday 10:56:01

d3fault
Member
Registered: Yesterday
Posts: 1

[AUR] batman-rs: a zero-allocation Netlink battery manager daemon

Hey everyone,

There are a few ways one can manage their computer's battery: adjusting brightness, switching power profiles, safe suspends, and so on. They work, but are limited in a couple of ways. One approach is writing a shell script that reads '/sys/class/power_supply/BAT0/capacity', compares the number, executes a command, and goes back to sleep... (been mine for a while :D). Not the best, as it prevents the CPU from reaching its deep sleep C-states, and at times introduces latency or dead wakes with no actionable changes.

We also have udev kernel-level rules, a better option over polling on intervals, but they are designed for device state changes (AC adapter plugs/unplugs). Capacity changes on discharge do trigger uevents, but udev isn't really intended for running arbitrary user commands on every battery tick. Then there's upower, used by GNOME and KDE, but it's overkill and too bloated for i3/Hyprland minimalists, myself included (Hyprland). upower pulls in a bunch of dependencies, polls the kernel, not a great start, and sends D-Bus signals that require dbus-monitor parsing... and whatnot.

I wrote batman-rs with a simple philosophy in mind: "Provide a reliable and efficient mechanism, and let the user design their own policies." It opens a raw AF_NETLINK socket and blocks. It only consumes cycles when the kernel broadcasts a capacity or state change event and, upon evaluation, executes user-defined rules. That's it! a clean mechanism... and the rest is user-defined policy. More on how it works can be found at the repo: https://github.com/DavidMANZI-093/batman-rs

I built this primarily on my HP EliteBook 840 G5 running Arch, so I would appreciate any code reviews, edge-case testing on different hardware, or feedback on the Netlink socket implementation.

Thanks!

(Please bear with me, it's my first time publishing something on the AUR, this is not slop. I know how things can be... back at the repo, my README was AI-assisted, that part is hard... but uhh, I'm truly invested in this, to say the least. I've done my homework :| )

Online

Board footer

Powered by FluxBB