Date: Sat, 24 Feb 2018 20:07:39 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329924 - head/stand/lua Message-ID: <201802242007.w1OK7dHU068542@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Sat Feb 24 20:07:39 2018 New Revision: 329924 URL: https://svnweb.freebsd.org/changeset/base/329924 Log: 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. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Sat Feb 24 20:00:31 2018 (r329923) +++ head/stand/lua/config.lua Sat Feb 24 20:07:39 2018 (r329924) @@ -124,19 +124,45 @@ pattern_table = { } } +local function read_file(name, silent) + local f = io.open(name) + if f == nil then + if not silent then + print("Failed to open config: '" .. name .. "'") + end + return nil + end + + local text, _ = io.read(f) + -- We might have read in the whole file, this won't be needed any more. + io.close(f) + + if text == nil then + if not silent then + print("Failed to read config: '" .. name .. "'") + end + return nil + end + return text +end + 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 + local text = read_file(nextboot_file, true) + if text == nil then + return end - if not config.processFile(nextboot_file, true, check_nextboot_enabled) - then - -- This only fails if it actually hit a parse error + 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 @@ -157,28 +183,6 @@ local function check_nextboot() end end -local function read_file(name, silent) - local f = io.open(name) - if f == nil then - if not silent then - print("Failed to open config: '" .. name .. "'") - end - return nil - end - - local text, _ = io.read(f) - -- We might have read in the whole file, this won't be needed any more. - io.close(f) - - if text == nil then - if not silent then - print("Failed to read config: '" .. name .. "'") - end - return nil - end - return text -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 @@ -335,13 +339,6 @@ function config.processFile(name, silent, check_and_ha local text = read_file(name, silent) if text == nil then 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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802242007.w1OK7dHU068542>