remove pidfile dependency of sock-connector
@@ -11,17 +11,11 @@ function serial_cleanup() {
# if this is a serial connection, see if there is a previous
# connection that must be cleaned up before starting a new one.
if is_console; then
- local pid_file=${SOCKET}.pid
- local pid=$(cat $pid_file 2>/dev/null)
- local my_pid=$$
- if [ -n "$pid" ] && [ -f "/proc/$pid/cmdline" ]; then
- local cmdline=$(cat /proc/$pid/cmdline 2>/dev/null | tr -d '\0')
- local my_cmdline=$(cat /proc/$my_pid/cmdline 2>/dev/null | tr -d '\0')
- if [ "$cmdline" = "$my_cmdline" ]; then
- kill $pid > /dev/null 2>&1
- fi
- fi
- echo "$$" > $pid_file
+ pgrep socat | while read pid; do
+ tr '\0' '\n' < "/proc/$pid/cmdline" \
+ | grep -qE "^$PROTOCOL:/$SOCKET$" || continue
+ kill "$pid"
+ done
fi
}
