From 5f4315c40ceeb6a9235cdaa4e5d758b777f72b1f Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 6 May 2019 08:33:27 +0200 Subject: [PATCH] system: stop using a lock around resolv.conf handling #2267 This might kill a bit of delay in function use by doing an atomic move to update resolv.conf. Even if several instances are running at the same time the contents of the file will be the same now. I don't expect issues with the DNS route updates either: even if they are removed or added twice, they will always end up being there. --- src/etc/inc/system.inc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 5b326d5fa..aaa54589b 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -179,10 +179,11 @@ function system_resolvconf_generate($verbose = false) } } - $dnslock = lock('resolvconf', LOCK_EX); + $tempfile = tempnam('/tmp', 'resolv.conf'); + file_put_contents($tempfile, $resolvconf); + chmod($tempfile, 0644); - file_put_contents('/etc/resolv.conf', $resolvconf); - chmod('/etc/resolv.conf', 0644); + rename($tempfile, '/etc/resolv.conf'); /* setup static routes for DNS servers. */ $gateways = new \OPNsense\Routing\Gateways(legacy_interfaces_details()); @@ -207,8 +208,6 @@ function system_resolvconf_generate($verbose = false) } } - unlock($dnslock); - if ($verbose) { echo "done.\n"; }