diff --git a/.build/Makefile b/.build/Makefile index 07cb0fd..23bff85 100644 --- a/.build/Makefile +++ b/.build/Makefile @@ -33,7 +33,7 @@ verify: clean: rm -f $(BUILD_DIR)/ifmqtoggle_*_all.ipk rm -f $(BUILD_DIR)/ifmqtoggle_*_all.ipk.sha256 - $(MAKE) -f $(BUILD_DIR)/Makefile down + @$(MAKE) -f $(BUILD_DIR)/Makefile down docker image rm -f $(IMAGE_NAME) package: build run copy down diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e9c706..acbec88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +## [1.1.1-1] - 2024-10-06 +### Fixed +- Patched an issue where reading the MQTT subscription PID could return a bad value depending on the configuration of `cat`. + ## [1.1.0-1] - 2024-05-31 ### Added - Listeners now include their name in log messages. @@ -10,6 +14,7 @@ ### Added - Initial release. -[Unreleased]: https://github.com/alex-massa/ifmqtoggle/compare/v1.1.0-1...HEAD +[Unreleased]: https://github.com/alex-massa/ifmqtoggle/compare/v1.1.1-1...HEAD +[1.1.1-1]: https://github.com/alex-massa/ifmqtoggle/compare/v1.1.0-1...v1.1.1-1 [1.1.0-1]: https://github.com/alex-massa/ifmqtoggle/compare/v1.0.0-1...v1.1.0-1 [1.0.0-1]: https://github.com/alex-massa/ifmqtoggle/commits/v1.0.0-1 diff --git a/Makefile b/Makefile index 48cbe58..ce339cb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ifmqtoggle -PKG_VERSION:=1.1.0 +PKG_VERSION:=1.1.1 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) diff --git a/src/ifmqtoggle b/src/ifmqtoggle index 4db97e0..15da61f 100644 --- a/src/ifmqtoggle +++ b/src/ifmqtoggle @@ -2,6 +2,7 @@ INSTANCE=$1 LOCKFILE="/tmp/lockfile_$$" +SHOULD_EXIT=false TGT_IFACE=$(uci -q get ifmqtoggle."$INSTANCE".iface) #WAN_IFACE=$(ip route | awk '/default/ { print $5 }') # unused, left for future reference @@ -25,12 +26,12 @@ tmp=$(uci -q get ifmqtoggle."$INSTANCE".mqtt_broker_retry_delay) MQTT_BROKER_RETRY_DELAY=${tmp:-5} cleanup() { - echo "[$INSTANCE]" "Cleaning up..." + echo "[$INSTANCE] Cleaning up process "$MQTT_SUB_PID"..." kill "$MQTT_SUB_PID" 2>/dev/null wait "$MQTT_SUB_PID" 2>/dev/null || true rm -f "$LOCKFILE" echo "[$INSTANCE]" "Cleanup complete" - exit 0 + SHOULD_EXIT=true } trap cleanup TERM @@ -64,12 +65,10 @@ handle_message() { fi } -echo "[$INSTANCE]" "Starting MQTT subscriber for topic $MQTT_TOPIC on broker $MQTT_BROKER_HOST:$MQTT_BROKER_PORT" while true; do - mqtt_sub_pidfile=$(mktemp -u) - exec 3< <(mosquitto_sub -F "%j" -h "$MQTT_BROKER_HOST" -p "$MQTT_BROKER_PORT" -t "$MQTT_TOPIC" ${MQTT_AUTH} ${MQTT_OPTIONS} & echo $! > "$mqtt_sub_pidfile") - MQTT_SUB_PID=$(cat "$mqtt_sub_pidfile") - rm -f "$mqtt_sub_pidfile" + echo "[$INSTANCE]" "Starting MQTT subscriber for topic $MQTT_TOPIC on broker $MQTT_BROKER_HOST:$MQTT_BROKER_PORT" + exec 3< <(mosquitto_sub -F "%j" -h "$MQTT_BROKER_HOST" -p "$MQTT_BROKER_PORT" -t "$MQTT_TOPIC" $(echo "$MQTT_AUTH" | xargs) $(echo "$MQTT_OPTIONS" | xargs) & pid=$!; echo $pid) + read -r MQTT_SUB_PID <&3 while read -r message <&3; do echo "[$INSTANCE]" "Received message: $message" if [ ! -f $LOCKFILE ]; then @@ -83,6 +82,9 @@ while true; do rm -f $LOCKFILE fi done + if [ "$SHOULD_EXIT" = true ]; then + break + fi echo "[$INSTANCE]" "Connection to MQTT broker failed, retrying in $MQTT_BROKER_RETRY_DELAY seconds..." sleep "$MQTT_BROKER_RETRY_DELAY" done