Overview
The kvand daemon is a Go program that provides privileged access to Lenovo laptop hardware through the ACPI interface. It runs as a separate process with root privileges and communicates with the GUI via stdin/stdout.- Language: Go
- Privilege level: Root (escalates via pkexec)
- Distribution: Embedded in JAR, extracted to
/tmpon startup - Repository: github.com/kosail/Kvand (separate repo)
The backend source code in the KVantage repository (
composeApp/src/jvmMain/resources/backend/main.go) is included for reference. The canonical source and development happens in the separate Kvand repository.Daemon Lifecycle
Embedding in JAR Resources
The compiled Go binary is placed in the JAR’s resources at build time:Why This Approach?
- Single-file distribution - Everything ships in one JAR
- No installation required - Users don’t need to manually place binaries
- Version consistency - Frontend and backend versions always match
- Simplicity - No package manager integration needed
Root Privilege Escalation
The daemon checks its effective GID and escalates if necessary:The escalateWithPkexec Function
pkexec, which:
- Shows a graphical password prompt (via PolicyKit)
- Re-runs the same binary as root
- Inherits stdin/stdout from the parent process
Password Prompt Timing
The password is requested once per session when the application starts. The daemon continues running with root privileges for the entire session, eliminating repeated prompts.Handshake Protocol
The frontend blocks on application startup until it receives theREADY message:
Backend sends:
Command Protocol
The daemon accepts line-based text commands via stdin.Command Parser
Command Syntax
Get Commands (2 tokens):get performance→ Returns0x0,0x1, or0x2get conservation→ Returns0x0(off) or0x1(on)get rapid→ Returns0x0(off) or0x1(on)
set performance 0→ Sets Intelligent Cooling mode, respondsOKset conservation 1→ Enables 80% charge limit, respondsOKset rapid 0→ Disables rapid charge, respondsOK
Parse Implementation
ACPI Interface Interaction
The acpi_call Kernel Module
The daemon requires theacpi_call kernel module, which exposes /proc/acpi/call for reading and writing ACPI methods.
Module check:
ACPI Command Constants
Lenovo-specific ACPI paths are hardcoded in the daemon:ACPI Write Operation
Writing to/proc/acpi/call invokes an ACPI method:
ACPI Read Operation
Reading from/proc/acpi/call retrieves the result of the last invocation:
Why Feedback Parameter?
From the code comments:Get vs Set Operations
Get Operation (query hardware state):ACPI Timing Characteristics
From the code comments:OK response before issuing another command. The ~1 second delay is handled naturally by the synchronous communication protocol.
Security Considerations
Root Requirement Justification
The/proc/acpi/call interface requires root access because:
- Direct hardware access - ACPI methods can control physical hardware
- System stability - Malformed ACPI calls can crash the system
- Security boundary - Prevents unprivileged users from changing power settings
Isolation Strategy
KVantage minimizes risk through:- Privilege separation - Only the small Go daemon runs as root
- Limited attack surface - Backend has no network access, no file system access (except
/proc/acpi/call) - Simple protocol - No complex parsing, no code execution
- Hardcoded commands - ACPI paths are constants, not user-controlled
- Short-lived - Daemon only runs while GUI is open
Input Validation
The daemon validates all input:Standalone Usage
While designed to be embedded, the daemon can be run standalone:Error Handling
The daemon uses colored output for diagnostics:Building the Backend
To compile the Go daemon:-s- Omit symbol table-w- Omit DWARF debug info- Result: Smaller binary size
External Development
For contributors working on the backend:- Clone the Kvand repository: github.com/kosail/Kvand
- Make changes and test standalone
- Copy the compiled binary to
composeApp/src/jvmMain/resources/backend/kvand - Rebuild the KVantage JAR
Platform Compatibility
The daemon is Linux-specific due to:/proc/acpi/calldependency (Linux kernel module)pkexecfor privilege escalation (PolicyKit)- Lenovo ACPI paths (hardware-specific)
acpi_callkernel module available- PolicyKit (pkexec) installed
- Lenovo laptop with compatible ACPI table