travelmate: fix possible race condition
authorDirk Brenken <dev@brenken.org>
Thu, 26 Nov 2020 21:39:15 +0000 (22:39 +0100)
committerDirk Brenken <dev@brenken.org>
Thu, 26 Nov 2020 21:39:15 +0000 (22:39 +0100)
* prevent possible duplicate script execution due to
  multiple ntp events in parallel

Signed-off-by: Dirk Brenken <dev@brenken.org>
net/travelmate/Makefile
net/travelmate/files/travelmate_ntp.hotplug

index 1f9935466c8366c9152a518d4802b756a19b3592..c74a33a08164d67efc591d126af2e5bc63212fa0 100644 (file)
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=travelmate
 PKG_VERSION:=2.0.2
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 PKG_LICENSE:=GPL-3.0-or-later
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
 
index 4a31d594672bf4f38ba2cedf9f67559a39ad6a6f..2a215e4ba4a4b32194542c2847a5e22529d0fee0 100755 (executable)
@@ -22,10 +22,14 @@ f_log()
        fi
 }
 
-if [ "${ACTION}" = "stratum" ] && [ ! -f "${trm_ntpfile}" ] && \
-       [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
+if [ "${ACTION}" = "stratum" ] && [ ! -f "${trm_ntpfile}" ] && [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
 then
-       > "${trm_ntpfile}"
-       f_log "info" "get ntp time sync"
-       "${trm_init}" restart
+       {
+               flock -xn 1001
+               if [ "$?" = "0" ]
+               then
+                       f_log "info" "get ntp time sync"
+                       "${trm_init}" restart
+               fi
+       } 1001>"${trm_ntpfile}"
 fi