Date: Sat, 24 Feb 2018 19:51:18 +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: r329922 - head/stand/lua Message-ID: <201802241951.w1OJpIou060324@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Sat Feb 24 19:51:18 2018 New Revision: 329922 URL: https://svnweb.freebsd.org/changeset/base/329922 Log: lualoader: Split config file I/O out into a separate function This is step 1 towards revoking config.parse of it I/O privileges. Ideally, all reading would be done before config.parse and config.parse would just take text and parse it rather than being charged with the entire process. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Sat Feb 24 19:40:23 2018 (r329921) +++ head/stand/lua/config.lua Sat Feb 24 19:51:18 2018 (r329922) @@ -156,6 +156,28 @@ 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 = {} @@ -311,25 +333,11 @@ function config.parse(name, silent, check_and_halt) if silent == nil then silent = false end - local f = io.open(name) - if f == nil then - if not silent then - print("Failed to open config: '" .. name .. "'") - end - return silent - end - local text, _ = io.read(f) - -- We might have read in the whole file, this won't be needed any more. - io.close(f) - + local text = read_file(name, silent) if text == nil then - if not silent then - print("Failed to read config: '" .. name .. "'") - end - return silent + return not silent end - if check_and_halt ~= nil then if not check_and_halt(text) then
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802241951.w1OJpIou060324>