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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to