Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jul 2014 21:09:30 GMT
From:      pedrosouza@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r270931 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua
Message-ID:  <201407152109.s6FL9U3q052020@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pedrosouza
Date: Tue Jul 15 21:09:29 2014
New Revision: 270931
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=270931

Log:
  Added kernel loading function

Modified:
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua	Tue Jul 15 20:35:56 2014	(r270930)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua	Tue Jul 15 21:09:29 2014	(r270931)
@@ -52,14 +52,14 @@
     [9] = {str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
     process = function(k, v) 
         if loader.perform(k) ~= 0 then
-            print("Failed to exec '"..k.."'");
+            print("Failed to exec '"..k.."'\n");
         end
     end },
 --  env_var="value"
     [10] = {str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
     process = function(k, v) 
-        if loader.perform("set "..k.."="..v) ~= 0 then
-            print("Failed to set '"..k.."' with value: "..v);
+        if loader.perform("set "..k.."=\""..v.."\"") ~= 0 then
+            print("Failed to set '"..k.."' with value: "..v.."\n");
         end
     end }
 };
@@ -73,7 +73,8 @@
     return true;
 end
 
-function config.loadmod(mod)
+function config.loadmod(mod, silent)
+    local status = true;
     for k, v in pairs(mod) do
         if v.load == "YES" then
             local str = "load ";
@@ -83,33 +84,38 @@
             
             if v.before ~= nil then
                 if loader.perform(v.before) ~= 0 then
-                    print("Failed to execute '"..v.before.."' before loading '"..k.."'\n");
+                    if not silent then print("Failed to execute '"..v.before.."' before loading '"..k.."'\n"); end
+                    status = false;
                 end
             end
             
             if loader.perform(str) ~= 0 then
-                print("Failed to execute '" .. str .. "'\n");
+                if not silent then print("Failed to execute '" .. str .. "'\n"); end
                 if v.error ~= nil then
                     loader.perform(v.error);
                 end 
+                status = false;
             end
             
             if v.after ~= nil then
                 if loader.perform(v.after) ~= 0 then
-                    print("Failed to execute '"..v.after.."' after loading '"..k.."'\n");
+                    if not silent then print("Failed to execute '"..v.after.."' after loading '"..k.."'\n"); end
+                    status = false;
                 end
             end
             
         else
-            print("Skiping module '".. k .. "'\n");
+            --if not silent then print("Skiping module '".. k .. "'\n"); end
         end
     end
+    
+    return status;
 end
 
-function config.parse(name)
+function config.parse(name, silent)
     local f = io.open(name);
     if f == nil then
-        print("Failed to open config : " .. name);
+        if not silent then print("Failed to open config : '" .. name.."'\n"); end
         return false;
     end
     
@@ -119,11 +125,12 @@
     text, r = io.read(f);
     
     if text == nil then
-        print("Failed to read confif : " .. name);
+        if not silent then print("Failed to read confif : '" .. name.."'\n"); end
         return false;
     end
     
     local n = 1;
+    local status = true;
     
     for line in string.gmatch(text, "([^\n]+)") do
     
@@ -138,7 +145,8 @@
                     if config.isValidComment(c) then
                         val.process(k, v);
                     else
-                        print("Malformed line ("..n.."):\n\t"..line.."\n");
+                        print("Malformed line ("..n.."):\n\t'"..line.."'\n");
+                        status = false;
                     end
                     
                     break;
@@ -146,9 +154,63 @@
             end
             
             if found == false then
-                print("Malformed line ("..n.."):\n\t"..line.."\n");
+                print("Malformed line ("..n.."):\n\t'"..line.."'\n");
+                status = false;
             end
         end
         n = n + 1;
     end
+    
+    return status;
+end
+
+function config.loadkernel()
+    local flags = loader.getenv("kernel_options") or "";
+ 
+    
+    local doload = function (names) 
+        for name in names:gmatch("([^;]+)%s*;?") do
+            r = loader.perform("load "..flags.." "..name);
+            if r == 0 then
+                return name;
+            end
+        end
+        return nil;
+    end;
+    
+    local envs = {"bootfile", "kernel"};
+    
+    for k, v in pairs(envs) do
+        local names = loader.getenv(v) or "";
+        local ret = doload(names);
+        if ret ~= nil then
+            print("Kernel '"..ret.."' loaded!\n");
+            return true;
+        end
+    end
+    return false;
+end
+
+function config.load(file)
+
+    if not file then file = "/boot/defaults/loader.conf"; end
+    
+    if not config.parse(file) then print("Failed to parse configuration: '"..file.."'\n"); end
+    
+    local f = loader.getenv("loader_conf_files");
+    if f ~= nil then
+        for name in string.gmatch(f, "([%w%p]+)%s*") do
+            if not config.parse(name) then print("Failed to parse configuration: '"..name.."'\n"); end
+        end
+    end
+
+    print("Loading kernel . . .\n");
+    config.loadkernel();
+
+    print("Loading configurations . . .\n");
+    if config.loadmod(modules) then
+        print("Configurations loaded successful!\n");
+    else
+        print("Configurations load failed!\n");
+    end
 end
\ No newline at end of file

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua	Tue Jul 15 20:35:56 2014	(r270930)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua	Tue Jul 15 21:09:29 2014	(r270931)
@@ -7,8 +7,10 @@
     end
 end
 
-print("Calling include...");
-
 include("/boot/menu.lua");
-print("Included menu.lua");
+include("/boot/password.lua");
+include("/boot/config.lua");
+
+config.load();
+password.check();
 menu.run();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407152109.s6FL9U3q052020>