From owner-svn-src-all@freebsd.org Sat Feb 24 19:51:19 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4246AF0A103; Sat, 24 Feb 2018 19:51:19 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E7BCA73ABD; Sat, 24 Feb 2018 19:51:18 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E131B2A03A; Sat, 24 Feb 2018 19:51:18 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1OJpIsp060325; Sat, 24 Feb 2018 19:51:18 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1OJpIou060324; Sat, 24 Feb 2018 19:51:18 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802241951.w1OJpIou060324@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 24 Feb 2018 19:51:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329922 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329922 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Feb 2018 19:51:19 -0000 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