From acca38ff8d4f52d4e28fed68f8c88618d9e036d3 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 13 Jan 2009 16:01:06 +0000 Subject: Modified fs.lua to survive nil parameters. Added create_directory and used within create_file and write_file. Reviewed each read_file call to make sure handles nil return value. git-svn-id: svn://svn.alpinelinux.org/acf/openntpd/trunk@1677 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openntpd-model.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'openntpd-model.lua') diff --git a/openntpd-model.lua b/openntpd-model.lua index a66160c..cbb0ab7 100644 --- a/openntpd-model.lua +++ b/openntpd-model.lua @@ -72,7 +72,7 @@ function read_config () config.listen = cfe({ type="list", value={}, label="Addresses to listen on", descr="List of IP addresses/hostnames to listen on. '*' means listen on all local addresses." }) config.setstimeonstartup = cfe({ type="boolean", value=false, label="Set time on startup" }) - local conf = format.parse_linesandwords(fs.read_file(configfile)) + local conf = format.parse_linesandwords(fs.read_file(configfile) or "") for i,line in ipairs(conf) do if line[1] == "server" then table.insert(config.server.value, line[2]) @@ -83,7 +83,7 @@ function read_config () end end - local opts = string.sub(format.parse_ini_file(fs.read_file(confdfile), "", "NTPD_OPTS"), 2, -2) + local opts = string.sub(format.parse_ini_file(fs.read_file(confdfile) or "", "", "NTPD_OPTS"), 2, -2) if format.opts_to_table(opts, "-s") then config.setstimeonstartup.value = true end @@ -99,7 +99,7 @@ function update_config(config) local reverseservers = {} for i,val in ipairs(config.value.servers.value) do reverseservers[val] = i end local reverselisten = {} for i,val in ipairs(config.value.listen.value) do reverselisten[val] = i end - local configcontent = string.gsub(fs.read_file(configfile), "\n+$", "") + local configcontent = string.gsub(fs.read_file(configfile) or "", "\n+$", "") local configlines = format.parse_linesandwords(configcontent) for i=#configlines,1,-1 do if configlines[i][1] == "server" then -- cgit v1.2.3