A walkthrough of powerctl, a 500-line Hare program that lets non-privileged Linux users manage power states (suspend, hibernate, etc.) via sysfs. The post covers key implementation details: using setuid with group-based access control, parsing space-separated sysfs files with a string tokenizer, writing to sysfs within its single-syscall constraint using buffered I/O, and handling edge cases like exhaustive switch statements and future kernel state additions. Serves as a practical case study demonstrating where the Hare language excels for small systems utilities.

8m read timeFrom drewdevault.com
Post cover image

Sort: