lualoader: throw out nextboot's usage of standard config processing

It should use the common parser, but it should not be processed like a
standard file. Rewite check_nextboot to read the file in, check whether it
should continue, then parse as needed.

This allows us to throw the recently introduced check_and_halt callback
swiftly out the window.
This commit is contained in:
Kyle Evans 2018-02-24 20:07:39 +00:00
parent 4adde50db2
commit ddfae7e314
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329924

View File

@ -124,39 +124,6 @@ pattern_table = {
}
}
local function check_nextboot()
local nextboot_file = loader.getenv("nextboot_file")
if nextboot_file == nil then
return
end
local function check_nextboot_enabled(text)
return text:match("^nextboot_enable=\"NO\"") == nil
end
if not config.processFile(nextboot_file, true, check_nextboot_enabled)
then
-- This only fails if it actually hit a parse error
print("Failed to parse nextboot configuration: '" ..
nextboot_file .. "'")
end
-- Attempt to rewrite the first line and only the first line of the
-- nextboot_file. We overwrite it with nextboot_enable="NO", then
-- check for that on load. See: check_nextboot_enabled
-- It's worth noting that this won't work on every filesystem, so we
-- won't do anything notable if we have any errors in this process.
local nfile = io.open(nextboot_file, 'w')
if nfile ~= nil then
-- We need the trailing space here to account for the extra
-- character taken up by the string nextboot_enable="YES"
-- Or new end quotation mark lands on the S, and we want to
-- rewrite the entirety of the first line.
io.write(nfile, "nextboot_enable=\"NO\" ")
io.close(nfile)
end
end
local function read_file(name, silent)
local f = io.open(name)
if f == nil then
@ -179,6 +146,43 @@ local function read_file(name, silent)
return text
end
local function check_nextboot()
local nextboot_file = loader.getenv("nextboot_file")
if nextboot_file == nil then
return
end
local text = read_file(nextboot_file, true)
if text == nil then
return
end
if text:match("^nextboot_enable=\"NO\"") ~= nil then
-- We're done; nextboot is not enabled
return
end
if not config.parse(text) then
print("Failed to parse nextboot configuration: '" ..
nextboot_file .. "'")
end
-- Attempt to rewrite the first line and only the first line of the
-- nextboot_file. We overwrite it with nextboot_enable="NO", then
-- check for that on load. See: check_nextboot_enabled
-- It's worth noting that this won't work on every filesystem, so we
-- won't do anything notable if we have any errors in this process.
local nfile = io.open(nextboot_file, 'w')
if nfile ~= nil then
-- We need the trailing space here to account for the extra
-- character taken up by the string nextboot_enable="YES"
-- Or new end quotation mark lands on the S, and we want to
-- rewrite the entirety of the first line.
io.write(nfile, "nextboot_enable=\"NO\" ")
io.close(nfile)
end
end
-- Module exports
-- Which variables we changed
config.env_changed = {}
@ -327,7 +331,7 @@ function config.loadmod(mod, silent)
return status
end
function config.processFile(name, silent, check_and_halt)
function config.processFile(name, silent)
if silent == nil then
silent = false
end
@ -337,13 +341,6 @@ function config.processFile(name, silent, check_and_halt)
return not silent
end
if check_and_halt ~= nil then
if not check_and_halt(text) then
-- We'll just pretend that everything is fine...
return true
end
end
return config.parse(text)
end