[source] dnsmasq: write atomic host file
LEDE Commits
lede-commits at lists.infradead.org
Thu Dec 7 01:59:11 PST 2017
dedeckeh pushed a commit to source.git, branch master:
https://git.lede-project.org/a39ddff4287e760f44a2d7bb44be364a0061d4bf
commit a39ddff4287e760f44a2d7bb44be364a0061d4bf
Author: Hans Dedecker <dedeckeh at gmail.com>
AuthorDate: Thu Dec 7 10:11:50 2017 +0100
dnsmasq: write atomic host file
Different invocations of the dnsmasq init script (e.g. at startup by procd)
will rewrite the dhcp host file which might result into dnsmasq reading an
empty dhcp host file as it is being rewritten by the dnsmasq init script.
Let the dnsmasq init script first write to a temp dhcp host file so it does
not overwrite the contents of the existing dhcp host file.
Reported-by: Hartmut Birr <e9hack at gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
---
package/network/services/dnsmasq/Makefile | 2 +-
package/network/services/dnsmasq/files/dnsmasq.init | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/package/network/services/dnsmasq/Makefile b/package/network/services/dnsmasq/Makefile
index 480a8a9..59beb98 100644
--- a/package/network/services/dnsmasq/Makefile
+++ b/package/network/services/dnsmasq/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=dnsmasq
PKG_VERSION:=2.78
-PKG_RELEASE:=5
+PKG_RELEASE:=6
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq/
diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index 8c40f3b..b84f531 100644
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -294,7 +294,7 @@ dhcp_host_add() {
config_get_bool dns "$cfg" dns 0
[ "$dns" = "1" -a -n "$ip" -a -n "$name" ] && {
- echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE
+ echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE_TMP
}
config_get mac "$cfg" mac
@@ -635,7 +635,7 @@ dhcp_domain_add() {
record="${record:+$record }$name"
done
- echo "$ip $record" >> $HOSTFILE
+ echo "$ip $record" >> $HOSTFILE_TMP
}
dhcp_srv_add() {
@@ -741,6 +741,7 @@ dnsmasq_start()
CONFIGFILE="${BASECONFIGFILE}.${cfg}"
CONFIGFILE_TMP="${CONFIGFILE}.$$"
HOSTFILE="${BASEHOSTFILE}.${cfg}"
+ HOSTFILE_TMP="${HOSTFILE}.$$"
BASEDHCPSTAMPFILE_CFG="${BASEDHCPSTAMPFILE}.${cfg}"
# before we can call xappend
@@ -751,7 +752,7 @@ dnsmasq_start()
chown dnsmasq:dnsmasq /var/run/dnsmasq
echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE_TMP
- echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE
+ echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE_TMP
local dnsmasqconffile="/etc/dnsmasq.${cfg}.conf"
if [ ! -r "$dnsmasqconffile" ]; then
@@ -998,6 +999,7 @@ dnsmasq_start()
echo >> $CONFIGFILE_TMP
mv -f $CONFIGFILE_TMP $CONFIGFILE
+ mv -f $HOSTFILE_TMP $HOSTFILE
[ "$resolvfile" = "/tmp/resolv.conf.auto" ] && {
rm -f /tmp/resolv.conf
More information about the lede-commits
mailing list