summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-24 11:28:05 +0200
committerSimon Rettberg2022-05-24 11:28:05 +0200
commit88c25a38f25fda411f196e3c25c7cbefdecc9c7d (patch)
treee606d57e7451b19a7e1818b8daac3b9bab2cd28a /core/modules/run-virt/data
parent[iptables-helper] Use cmp instead of diff (diff)
downloadmltk-88c25a38f25fda411f196e3c25c7cbefdecc9c7d.tar.gz
mltk-88c25a38f25fda411f196e3c25c7cbefdecc9c7d.tar.xz
mltk-88c25a38f25fda411f196e3c25c7cbefdecc9c7d.zip
[run-virt] Fix race condition in dhcpd config generator
Diffstat (limited to 'core/modules/run-virt/data')
-rwxr-xr-xcore/modules/run-virt/data/opt/openslx/scripts/runvirt-start_dhcpd15
1 files changed, 9 insertions, 6 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/scripts/runvirt-start_dhcpd b/core/modules/run-virt/data/opt/openslx/scripts/runvirt-start_dhcpd
index 3b2ef5e4..60cf7333 100755
--- a/core/modules/run-virt/data/opt/openslx/scripts/runvirt-start_dhcpd
+++ b/core/modules/run-virt/data/opt/openslx/scripts/runvirt-start_dhcpd
@@ -44,19 +44,22 @@ done
[ -z "$NTPSRV" ] && NTPSRV="0.0.0.0"
[ -z "${SLX_NET_WINS}" ] && SLX_NET_WINS=$(getips "$SLX_NET_DOMAIN")
[ -z "${SLX_NET_WINS}" ] && SLX_NET_WINS="0.0.0.0"
-sed "s#%DNSSERVER%#${SLX_DNS}#;s#%DOMAIN%#${SLX_NET_DOMAIN}#;s#%SEARCH%#${SLX_NET_SEARCH}#;s#%WINS%#${SLX_NET_WINS}#;s#%NTPSERVER%#${NTPSRV}#" "${DHCP_NAT_CONF}.template" > "${DHCP_NAT_CONF}.tmp"
+sed "s#%DNSSERVER%#${SLX_DNS}#;s#%DOMAIN%#${SLX_NET_DOMAIN}#;s#%SEARCH%#${SLX_NET_SEARCH}#;s#%WINS%#${SLX_NET_WINS}#;s#%NTPSERVER%#${NTPSRV}#" "${DHCP_NAT_CONF}.template" > "${DHCP_NAT_CONF}.$$"
# Make sure the primary vm running (we most likely never run more than one at a time anyways) always gets the same ip
-echo "static_lease $(echo "$MACADDRPREFIX:$MACADDRSUFFIX" | sed 's/%VMID%/01/') 192.168.101.20" >> "${DHCP_NAT_CONF}.tmp"
+echo "static_lease $(echo "$MACADDRPREFIX:$MACADDRSUFFIX" | sed 's/%VMID%/01/') 192.168.101.20" >> "${DHCP_NAT_CONF}.$$"
mkdir -p /var/lib/udhcpd
-if [ -s "${DHCP_NAT_CONF}" ] && cmp -s "${DHCP_NAT_CONF}.tmp" "${DHCP_NAT_CONF}"; then
- # Same, nothing to do
- rm -f -- "${DHCP_NAT_CONF}.tmp"
+if [ -s "${DHCP_NAT_CONF}" ] && cmp -s "${DHCP_NAT_CONF}.$$" "${DHCP_NAT_CONF}"; then
+ # Files are the same, nothing to do
+ rm -f -- "${DHCP_NAT_CONF}.$$"
+elif [ -s "${DHCP_NAT_CONF}" ] && [ "${DHCP_NAT_CONF}.$$" -ot "${DHCP_NAT_CONF}" ]; then
+ # Lost race
+ rm -f -- "${DHCP_NAT_CONF}.$$"
else
# Changed, replace and restart
- mv -f -- "${DHCP_NAT_CONF}.tmp" "${DHCP_NAT_CONF}"
+ mv -f -- "${DHCP_NAT_CONF}.$$" "${DHCP_NAT_CONF}"
echo "NAT1 dhcpd config changed; restarting service..."
systemctl --no-block try-restart run-virt-dhcpd.service
fi