svn commit: r329922 - head/stand/lua

Kyle Evans kevans at FreeBSD.org
Sat Feb 24 19:51:19 UTC 2018


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


More information about the svn-src-all mailing list