From owner-svn-src-head@freebsd.org Sat Mar 24 04:00:02 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 6A8B8F67CBF; Sat, 24 Mar 2018 04:00:02 +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 1907475E63; Sat, 24 Mar 2018 04:00:02 +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 EE6441836; Sat, 24 Mar 2018 04:00:01 +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 w2O40115049007; Sat, 24 Mar 2018 04:00:01 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2O4011C049006; Sat, 24 Mar 2018 04:00:01 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201803240400.w2O4011C049006@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 24 Mar 2018 04:00:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331476 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 331476 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: Sat, 24 Mar 2018 04:00:02 -0000 Author: kevans Date: Sat Mar 24 04:00:01 2018 New Revision: 331476 URL: https://svnweb.freebsd.org/changeset/base/331476 Log: lualoader: Make config env-related bits private API This pertains exclusively to the set/restore functionality that we offer, where any changes made by loader.conf previously will be effectively removed upon reload of the configuration. We don't currently have a need to export these, so don't bother. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Sat Mar 24 02:01:25 2018 (r331475) +++ head/stand/lua/config.lua Sat Mar 24 04:00:01 2018 (r331476) @@ -34,6 +34,10 @@ local hook = require("hook") local config = {} local modules = {} local carousel_choices = {} +-- Which variables we changed +local env_changed = {} +-- Values to restore env to (nil to unset) +local env_restore = {} local MSG_FAILEXEC = "Failed to exec '%s'" local MSG_FAILSETENV = "Failed to '%s' with value: %s" @@ -50,6 +54,44 @@ local MSG_KERNLOADING = "Loading kernel..." local MSG_MODLOADING = "Loading configured modules..." local MSG_MODLOADFAIL = "Could not load one or more modules!" +local function restoreEnv() + -- Examine changed environment variables + for k, v in pairs(env_changed) do + local restore_value = env_restore[k] + if restore_value == nil then + -- This one doesn't need restored for some reason + goto continue + end + local current_value = loader.getenv(k) + if current_value ~= v then + -- This was overwritten by some action taken on the menu + -- most likely; we'll leave it be. + goto continue + end + restore_value = restore_value.value + if restore_value ~= nil then + loader.setenv(k, restore_value) + else + loader.unsetenv(k) + end + ::continue:: + end + + env_changed = {} + env_restore = {} +end + +local function setEnv(key, value) + -- Track the original value for this if we haven't already + if env_restore[key] == nil then + env_restore[key] = {value = loader.getenv(key)} + end + + env_changed[key] = value + + return loader.setenv(key, value) +end + local pattern_table = { { str = "^%s*(#.*)", @@ -120,7 +162,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 + if setEnv(k, v) ~= 0 then print(MSG_FAILSETENV:format(k, v)) end end, @@ -129,7 +171,7 @@ local pattern_table = { { str = "^%s*([%w%p]+)%s*=%s*(%d+)%s*(.*)", process = function(k, v) - if config.setenv(k, v) ~= 0 then + if setEnv(k, v) ~= 0 then print(MSG_FAILSETENV:format(k, tostring(v))) end end, @@ -195,10 +237,6 @@ local function checkNextboot() end -- Module exports --- Which variables we changed -config.env_changed = {} --- Values to restore env to (nil to unset) -config.env_restore = {} config.verbose = false -- The first item in every carousel is always the default item. @@ -214,44 +252,6 @@ function config.setCarouselIndex(id, idx) carousel_choices[id] = idx end -function config.restoreEnv() - -- Examine changed environment variables - for k, v in pairs(config.env_changed) do - local restore_value = config.env_restore[k] - if restore_value == nil then - -- This one doesn't need restored for some reason - goto continue - end - local current_value = loader.getenv(k) - if current_value ~= v then - -- This was overwritten by some action taken on the menu - -- most likely; we'll leave it be. - goto continue - end - restore_value = restore_value.value - if restore_value ~= nil then - loader.setenv(k, restore_value) - else - loader.unsetenv(k) - end - ::continue:: - end - - config.env_changed = {} - config.env_restore = {} -end - -function config.setenv(key, value) - -- Track the original value for this if we haven't already - if config.env_restore[key] == nil then - config.env_restore[key] = {value = loader.getenv(key)} - end - - config.env_changed[key] = value - - return loader.setenv(key, value) -end - -- name here is one of 'name', 'type', flags', 'before', 'after', or 'error.' -- These are set from lines in loader.conf(5): ${key}_${name}="${value}" where -- ${key} is a module name. @@ -503,7 +503,7 @@ end -- Reload configuration function config.reload(file) modules = {} - config.restoreEnv() + restoreEnv() config.load(file) hook.runAll("config.reloaded") end