From owner-svn-src-head@freebsd.org Thu Mar 1 02:31:29 2018 Return-Path: Delivered-To: svn-src-head@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 85F09F39C42; Thu, 1 Mar 2018 02:31:29 +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 384E3735F4; Thu, 1 Mar 2018 02:31:29 +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 331EE222BB; Thu, 1 Mar 2018 02:31:29 +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 w212VSb0030647; Thu, 1 Mar 2018 02:31:28 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w212VS7S030646; Thu, 1 Mar 2018 02:31:28 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201803010231.w212VS7S030646@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 1 Mar 2018 02:31:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330139 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 330139 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Mar 2018 02:31:29 -0000 Author: kevans Date: Thu Mar 1 02:31:28 2018 New Revision: 330139 URL: https://svnweb.freebsd.org/changeset/base/330139 Log: lualoader: config: Pull some messages out into constants Rather than hardcoding these things. This could lead to some form of loader localization later, but the main goal at the moment is to get a clear view of the strings we're outputting and strive to use more string.format() and less wild concatenation all over the place. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Thu Mar 1 02:04:26 2018 (r330138) +++ head/stand/lua/config.lua Thu Mar 1 02:31:28 2018 (r330139) @@ -30,11 +30,24 @@ -- local config = {} - local modules = {} - local carousel_choices = {} +local MSG_FAILEXEC = "Failed to exec '%s'" +local MSG_FAILSETENV = "Failed to '%s' with value: %s" +local MSG_FAILOPENCFG = "Failed to open config: '%s'" +local MSG_FAILREADCFG = "Failed to read config: '%s'" +local MSG_FAILPARSECFG = "Failed to parse config: '%s'" +local MSG_FAILEXBEF = "Failed to execute '%s' before loading '%s'" +local MSG_FAILEXMOD = "Failed to execute '%s'" +local MSG_FAILEXAF = "Failed to execute '%s' after loading '%s'" +local MSG_MALFORMED = "Malformed line (%d):\n\t'%s'" +local MSG_DEFAULTKERNFAIL = "No kernel set, failed to load from module_path" +local MSG_KERNFAIL = "Failed to load kernel '%s'" +local MSG_KERNLOADING = "Loading kernel..." +local MSG_MODLOADING = "Loading configured modules..." +local MSG_MODLOADFAIL = "Could not load one or more modules!" + local pattern_table = { { str = "^%s*(#.*)", @@ -97,7 +110,7 @@ local pattern_table = { str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, _) if loader.perform(k) ~= 0 then - print("Failed to exec '" .. k .. "'") + print(MSG_FAILEXEC:format(k)) end end, }, @@ -106,8 +119,7 @@ local pattern_table = { str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) if config.setenv(k, v) ~= 0 then - print("Failed to set '" .. k .. - "' with value: " .. v .. "") + print(MSG_FAILSETENV:format(k, v)) end end, }, @@ -116,8 +128,7 @@ local pattern_table = { str = "^%s*([%w%p]+)%s*=%s*(%d+)%s*(.*)", process = function(k, v) if config.setenv(k, v) ~= 0 then - print("Failed to set '" .. k .. - "' with value: " .. v .. "") + print(MSG_FAILSETENV:format(k, tostring(v))) end end, }, @@ -127,7 +138,7 @@ local function readFile(name, silent) local f = io.open(name) if f == nil then if not silent then - print("Failed to open config: '" .. name .. "'") + print(MSG_FAILOPENCFG:format(name)) end return nil end @@ -138,7 +149,7 @@ local function readFile(name, silent) if text == nil then if not silent then - print("Failed to read config: '" .. name .. "'") + print(MSG_FAILREADCFG:format(name)) end return nil end @@ -162,8 +173,7 @@ local function checkNextboot() end if not config.parse(text) then - print("Failed to parse nextboot configuration: '" .. - nextboot_file .. "'") + print(MSG_FAILPARSECFG:format(nextbootfile)) end -- Attempt to rewrite the first line and only the first line of the @@ -264,6 +274,7 @@ end function config.loadmod(mod, silent) local status = true + local pstatus = true for k, v in pairs(mod) do if v.load == "YES" then local str = "load " @@ -278,23 +289,17 @@ function config.loadmod(mod, silent) else str = str .. k end - if v.before ~= nil then - if loader.perform(v.before) ~= 0 then - if not silent then - print("Failed to execute '" .. - v.before .. - "' before loading '" .. k .. - "'") - end - status = false + pstatus = loader.perform(v.before) == 0 + if not pstatus and not silent then + print(MSG_FAILEXBEF:format(v.before, k)) end + status = status and pstatus end if loader.perform(str) ~= 0 then if not silent then - print("Failed to execute '" .. str .. - "'") + print(MSG_FAILEXMOD:format(str)) end if v.error ~= nil then loader.perform(v.error) @@ -303,15 +308,11 @@ function config.loadmod(mod, silent) end if v.after ~= nil then - if loader.perform(v.after) ~= 0 then - if not silent then - print("Failed to execute '" .. - v.after .. - "' after loading '" .. k .. - "'") - end - status = false + pstatus = loader.perform(v.after) == 0 + if not pstatus and not silent then + print(MSG_FAILEXAF:format(v.after, k)) end + status = status and pstatus end -- else @@ -357,8 +358,8 @@ function config.parse(text) if config.isValidComment(c) then val.process(k, v) else - print("Malformed line (" .. n .. - "):\n\t'" .. line .. "'") + print(MSG_MALFORMED:format(n, + line)) status = false end @@ -367,8 +368,7 @@ function config.parse(text) end if not found then - print("Malformed line (" .. n .. "):\n\t'" .. - line .. "'") + print(MSG_MALFORMED:format(n, line)) status = false end end @@ -417,7 +417,7 @@ function config.loadKernel(other_kernel) config.kernel_loaded = nil return true else - print("No kernel set, failed to load from module_path") + print(MSG_DEFAULTKERNFAIL) return false end else @@ -455,7 +455,7 @@ function config.loadKernel(other_kernel) config.kernel_loaded = kernel return true else - print("Failed to load kernel '" .. kernel .. "'") + print(MSG_KERNFAIL:format(kernel)) return false end end @@ -471,7 +471,7 @@ function config.load(file) end if not config.processFile(file) then - print("Failed to parse configuration: '" .. file .. "'") + print(MSG_FAILPARSECFG:format(file)) end local f = loader.getenv("loader_conf_files") @@ -481,8 +481,7 @@ function config.load(file) -- silent parse so that we complain on parse errors but -- not for them simply not existing. if not config.processFile(name, true) then - print("Failed to parse configuration: '" .. - name .. "'") + print(MSG_FAILPARSECFG:format(name)) end end end @@ -504,17 +503,16 @@ function config.loadelf() local kernel = config.kernel_selected or config.kernel_loaded local loaded - print("Loading kernel...") + print(MSG_KERNLOADING) loaded = config.loadKernel(kernel) if not loaded then - print("Failed to load any kernel") return end - print("Loading configured modules...") + print(MSG_MODLOADING) if not config.loadmod(modules) then - print("Could not load one or more modules!") + print(MSG_MODLOADFAIL) end end