From: Michael Tremer Date: Tue, 12 May 2026 16:02:12 +0000 (+0100) Subject: knot-resolver: Create a helper function that will call functions on changes X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4040f21cbd7a5859c4e338c4cb2264d643ca7eca;p=ipfire-2.x.git knot-resolver: Create a helper function that will call functions on changes Signed-off-by: Michael Tremer --- diff --git a/config/knot-resolver/kresd.conf b/config/knot-resolver/kresd.conf index e54978742..f0fe64134 100644 --- a/config/knot-resolver/kresd.conf +++ b/config/knot-resolver/kresd.conf @@ -9,7 +9,36 @@ log_target("syslog") log_level("info") -- log_level("debug") +-- Load required Lua modules +local bit = require("bit") local csv = require("csv") +local notify = require("cqueues.notify") + +-- Helper function which will call a function if a given file has been changed +local function call_on_change(path, callback) + -- Split the path into parent directory and filename + local dir, file = string.match(path, "(.*)/([^/]+)") + + -- If we could not split the path (e.g. because it doesn't contain a /) + -- we will assume the file is in the current working directory + if not dir and not file then + dir = "." + file = path + end + + -- Create a new watcher for the directory + local watcher = notify.opendir(dir) + + -- Wake up when the file has changed + watcher:add(file, bit.bxor(notify.CREATE, notify.MODIFY)) + + -- Register a function that will call the callback on any changes + worker.coroutine(function() + for _, name in watcher:changes() do + callback() + end + end) +end local ETHERNET_SETTINGS_FILE = "/var/ipfire/ethernet/settings" local DNS_SETTINGS_FILE = "/var/ipfire/dns/settings"