]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
knot-resolver: Create a helper function that will call functions on changes
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 May 2026 16:02:12 +0000 (17:02 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 May 2026 15:27:29 +0000 (15:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/knot-resolver/kresd.conf

index e54978742ff1b27d94ca2320b9e5c9f833fbcf0c..f0fe641346dc1774721fcc0803779a50087f1d7f 100644 (file)
@@ -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"