Enforce single-instance in socktop-gestures instead of documenting it

The documented restart was `pkill -x lisgd && socktop-gestures &`. pkill exits
non-zero when it matches nothing, so `&&` short-circuits and the daemon
silently does not start when none was running -- you swipe, get nothing, and
reasonably blame the config change you just made. socktop-gestures exec'd lisgd
with no guard, so nothing downstream caught it.

Rather than only fixing the one-liner, move the invariant into the tool: it now
exits non-zero if a daemon is already running, and --replace stops the old one
first (waiting for it to actually exit). This is the failure the README itself
flags as gotcha 3, so a false success there is expensive.

Verified against a live daemon: refusal, --help, bad-option exit codes, and a
clean pid handover under --replace with the carousel still working.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
jasonwitty
2026-08-09 02:29:36 -07:00
parent 18ddd39184
commit 9a47fd47a7
3 changed files with 60 additions and 15 deletions
+6 -13
View File
@@ -1,20 +1,13 @@
#!/bin/sh
# Run the real gesture daemon in the foreground, with logging, so you can watch
# the display while you swipe. Ctrl-C to stop.
# Run the real gesture daemon in the foreground so you can watch the display
# while you swipe. Ctrl-C to stop.
#
# Expect: swipe right-to-left -> zooms in one host at a time
# swipe left-to-right -> walks back out to the overview
# "Execute ..." in the output means a gesture matched and fired.
#
# Make sure no other instance is running first -- two copies fire every swipe
# twice, which looks like the carousel skipping.
# Pass --replace to take over from an already-running daemon; without it,
# socktop-gestures refuses to start a second instance (which would make every
# swipe fire twice).
set -eu
if pgrep -x lisgd >/dev/null 2>&1; then
echo "!! lisgd is already running (pid: $(pgrep -x lisgd | tr '\n' ' '))." >&2
echo "!! Two instances make every swipe fire twice. Stop it first:" >&2
echo " pkill -x lisgd" >&2
exit 1
fi
exec "$(dirname "$0")/../socktop-gestures" -v
exec "$(dirname "$0")/../socktop-gestures" -v "$@"