diff --git a/package/gluon-wan-dnsmasq/files/etc/config/gluon-wan-dnsmasq b/package/gluon-wan-dnsmasq/files/etc/config/gluon-wan-dnsmasq index 748eecbf..9c7e9b4c 100644 --- a/package/gluon-wan-dnsmasq/files/etc/config/gluon-wan-dnsmasq +++ b/package/gluon-wan-dnsmasq/files/etc/config/gluon-wan-dnsmasq @@ -1,2 +1,2 @@ config 'static' - # list 'server' '192.168.0.1' # Example + # list 'server' '192.168.0.1' # Example diff --git a/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/update.lua b/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/update.lua index 0f97e0bd..88a86507 100755 --- a/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/update.lua +++ b/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/update.lua @@ -9,27 +9,38 @@ local uci = require('luci.model.uci').cursor() local fs = require 'nixio.fs' -local function write_servers(f, servers) +local new_servers = '' + + +local function append_servers(servers) for _, server in ipairs(servers) do - f:write('nameserver ', server, '\n') + new_servers = new_servers .. 'nameserver ' .. server .. '\n' end end -local function write_interface_servers(f, iface) - write_servers(f, ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server']) +local function append_interface_servers(iface) + append_servers(ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server']) end -fs.mkdirr(RESOLV_CONF_DIR) -local f = io.open(RESOLV_CONF, 'w+') - local static = uci:get_first('gluon-wan-dnsmasq', 'static', 'server') if type(static) == 'table' and #static > 0 then - write_servers(f, static) + append_servers(static) else - pcall(write_interface_servers, f, 'wan6') - pcall(write_interface_servers, f, 'wan') + pcall(append_interface_servers, 'wan6') + pcall(append_interface_servers, 'wan') end -f:close() + +fs.mkdirr(RESOLV_CONF_DIR) + +local old_servers = fs.readfile(RESOLV_CONF) + +if new_servers ~= old_servers then + local f = io.open(RESOLV_CONF .. '.tmp', 'w') + f:write(new_servers) + f:close() + + fs.rename(RESOLV_CONF .. '.tmp', RESOLV_CONF) +end