Unbound: fix file lock race in odhcpd.sh
authorTed Hess <thess@kitschensync.net>
Sat, 2 Nov 2024 15:31:05 +0000 (11:31 -0400)
committerTed Hess <thess@kitschensync.net>
Sun, 10 Nov 2024 16:50:19 +0000 (11:50 -0500)
Signed-off-by: Ted Hess <thess@kitschensync.net>
net/unbound/Makefile
net/unbound/files/odhcpd.sh

index 810858dee6c82f148494b05a506fcbd041596890..e3d128a522c0b060dd20d9722909441276e8236e 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=unbound
 PKG_VERSION:=1.21.0
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://nlnetlabs.nl/downloads/unbound
index b8af615a51fba36cd78f680bfd09d3c312e22125..9a428563b6bfa40f0239193406974a2c008f30de 100644 (file)
@@ -78,7 +78,6 @@ odhcpd_zonedata() {
       fi
     fi
 
-
     case $longconf in
     freshstart)
       awk -v conffile=$UB_DHCP_CONF -v pipefile=$dns_ls_new \
@@ -129,22 +128,11 @@ odhcpd_zonedata() {
 
 ##############################################################################
 
-UB_ODHPCD_LOCK=/tmp/unbound_odhcpd.lock
+UB_ODHCPD_LOCK=/var/lock/unbound_odhcpd.lock
 
-if [ ! -f $UB_ODHPCD_LOCK ] ; then
-  # imperfect but it should avoid collisions
-  touch $UB_ODHPCD_LOCK
+exec 1000>$UB_ODHCPD_LOCK
+if flock -x -n 1000 ; then
   odhcpd_zonedata
-  rm -f $UB_ODHPCD_LOCK
-
-else
-  UB_ODHCPD_LOCK_AGE=$(( $( date +%s ) - $( date -r $UB_ODHPCD_LOCK +%s ) ))
-
-  if [ $UB_ODHCPD_LOCK_AGE -gt 100 ] ; then
-    # unlock because something likely broke but do not write this time through
-    rm -f $UB_ODHPCD_LOCK
-  fi
 fi
 
 ##############################################################################
-