From 301dccec33ac87af4584096047cab8332b80c781 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Fri, 6 Feb 2026 17:21:07 +0100 Subject: [PATCH] fix(secubox-core): Prevent duplicate avahi-publish processes in mesh discovery Track avahi-publish PID in /tmp/secubox-avahi-mesh.pid and check if process is still running before spawning a new one. Prevents process accumulation when discover_peers() is called repeatedly. Co-Authored-By: Claude Opus 4.5 --- .../secubox-core/root/usr/lib/secubox/p2p-mesh.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/package/secubox/secubox-core/root/usr/lib/secubox/p2p-mesh.sh b/package/secubox/secubox-core/root/usr/lib/secubox/p2p-mesh.sh index 465cd6f1..bfe03344 100644 --- a/package/secubox/secubox-core/root/usr/lib/secubox/p2p-mesh.sh +++ b/package/secubox/secubox-core/root/usr/lib/secubox/p2p-mesh.sh @@ -284,9 +284,20 @@ discover_peers() { echo "$msg" | socat - UDP-DATAGRAM:255.255.255.255:$DISCOVERY_PORT,broadcast fi - # Also try mDNS if available + # Also try mDNS if available (only start if not already running) + local avahi_pid_file="/tmp/secubox-avahi-mesh.pid" if command -v avahi-publish >/dev/null; then + # Check if avahi-publish is already running for this service + if [ -f "$avahi_pid_file" ]; then + local old_pid=$(cat "$avahi_pid_file" 2>/dev/null) + if [ -n "$old_pid" ] && kill -0 "$old_pid" 2>/dev/null; then + # Already running, skip + return 0 + fi + fi + # Start new avahi-publish and save PID avahi-publish -s "secubox-mesh-$node_id" _secubox._tcp $MESH_PORT & + echo $! > "$avahi_pid_file" fi }