prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeye...
authorMatthew Wild <mwild1@gmail.com>
Thu, 11 Feb 2010 11:31:14 +0000 (11:31 +0000)
committerMatthew Wild <mwild1@gmail.com>
Thu, 11 Feb 2010 11:31:14 +0000 (11:31 +0000)
prosody
prosodyctl

diff --git a/prosody b/prosody
index 9e41c27711186f78dab18504216101728088b891..df7ce9fb9154da83622aaee785d8889a068ccc4c 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -32,34 +32,6 @@ if CFG_DATADIR then
        end
 end
 
--- Initialize logging
-require "core.loggingmanager"
-
--- Check runtime dependencies
-if not require "util.dependencies".check_dependencies() then
-       os.exit(1);
-end
-
--- Replace require() with one that doesn't pollute _G, required
--- for neat sandboxing of modules
-do
-       local _realG = _G;
-       local _real_require = require;
-       function require(...)
-               local curr_env = getfenv(2);
-               local curr_env_mt = getmetatable(getfenv(2));
-               local _realG_mt = getmetatable(_realG);
-               if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
-                       local old_newindex
-                       old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env;
-                       local ret = _real_require(...);
-                       _realG_mt.__newindex = old_newindex;
-                       return ret;
-               end
-               return _real_require(...);
-       end
-end
-
 -- Load the config-parsing module
 config = require "core.configmanager"
 
@@ -119,6 +91,38 @@ function load_libraries()
        server = require "net.server"
 end    
 
+function init_logging()
+       -- Initialize logging
+       require "core.loggingmanager"
+end
+
+function check_dependencies()
+       -- Check runtime dependencies
+       if not require "util.dependencies".check_dependencies() then
+               os.exit(1);
+       end
+end
+
+function sandbox_require()
+       -- Replace require() with one that doesn't pollute _G, required
+       -- for neat sandboxing of modules
+       local _realG = _G;
+       local _real_require = require;
+       function require(...)
+               local curr_env = getfenv(2);
+               local curr_env_mt = getmetatable(getfenv(2));
+               local _realG_mt = getmetatable(_realG);
+               if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
+                       local old_newindex
+                       old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env;
+                       local ret = _real_require(...);
+                       _realG_mt.__newindex = old_newindex;
+                       return ret;
+               end
+               return _real_require(...);
+       end
+end
+
 function init_global_state()
        bare_sessions = {};
        full_sessions = {};
@@ -407,7 +411,12 @@ function cleanup()
 end
 
 -- Are you ready? :)
+-- These actions are in a strict order, as many depend on
+-- previous steps to have already been performed
 read_config();
+init_logging();
+check_dependencies();
+sandbox_require();
 load_libraries();
 init_global_state();
 read_version();
index 70474900f3ea1593299d2a8e3b9b5118ddb828b2..9d2df69ede44490de53a6b36dca856aa04595638 100755 (executable)
@@ -29,12 +29,6 @@ if CFG_DATADIR then
        end
 end
 
-require "core.loggingmanager"
-
-if not require "util.dependencies".check_dependencies() then
-       os.exit(1);
-end
-
 config = require "core.configmanager"
 
 do
@@ -63,6 +57,12 @@ do
        end
 end
 
+require "core.loggingmanager"
+
+if not require "util.dependencies".check_dependencies() then
+       os.exit(1);
+end
+
 prosody = { hosts = {}, events = events, platform = "posix" };
 
 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data";