Commit c53e4731 by PLN (Algolia)

midi-autoconnect: rule 4 costs one aconnect per tick while healthy

Bash regex instead of a grep fork, and the driver's own virtual port as proof
of service so systemctl is only asked when the raw board is present without
it.
parent 34b60d4a
......@@ -199,17 +199,22 @@ DRIVER_TRIES=0
DRIVER_LAST=0
DRIVER_STATE=""
raw_lcxl3_present() {
aconnect -l 2>/dev/null | grep -Eq "^client [0-9]+: 'LCXL3[^']*' \[type=kernel"
}
ensure_surface_driver() {
local now
if ! raw_lcxl3_present; then
# One aconnect per tick and no systemctl while healthy: this loop runs every
# 2 s for the whole session, and forks are its whole cost. The driver's own
# virtual port is the proof it is serving; only when that port is missing
# while the raw board is present do we ask systemd.
local now ac
local raw_re="client [0-9]+: 'LCXL3[^']*' \[type=kernel"
ac="$(aconnect -l 2>/dev/null)"
if ! [[ "$ac" =~ $raw_re ]]; then
DRIVER_TRIES=0
DRIVER_STATE="absent"
return 0
fi
if [[ "$ac" == *"'ParVagues LCXL3"* ]] && [ "$DRIVER_STATE" = "up" ]; then
return 0 # steady state: zero extra forks
fi
if systemctl --user is-active --quiet "$DRIVER_UNIT"; then
if [ "$DRIVER_STATE" != "up" ]; then
echo "midi-autoconnect: LCXL3 present, lcxl3-driver is up"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment