Merge 0.9->0.10
[prosody.git] / prosody
diff --git a/prosody b/prosody
index b411370fb1f0b63e4d8ed0f9d7c24061525c8545..e8f81d5d6ec6a8144237cd37635a7f142c303ba7 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -49,9 +49,6 @@ _G.prosody = prosody;
 
 -- Check dependencies
 local dependencies = require "util.dependencies";
-if not dependencies.check_dependencies() then
-       os.exit(1);
-end
 
 -- Load the config-parsing module
 config = require "core.configmanager"
@@ -116,6 +113,12 @@ function read_config()
        end
 end
 
+function check_dependencies()
+       if not dependencies.check_dependencies() then
+               os.exit(1);
+       end
+end
+
 function load_libraries()
        -- Load socket framework
        server = require "net.server"
@@ -148,9 +151,12 @@ function sandbox_require()
        -- for neat sandboxing of modules
        local _realG = _G;
        local _real_require = require;
-       if not getfenv then
+       local getfenv = getfenv or function (f)
                -- FIXME: This is a hack to replace getfenv() in Lua 5.2
-               function getfenv(f) return debug.getupvalue(debug.getinfo(f or 1).func, 1); end
+               local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
+               if name == "_ENV" then
+                       return env;
+               end
        end
        function require(...)
                local curr_env = getfenv(2);
@@ -382,6 +388,7 @@ init_logging();
 sanity_check();
 sandbox_require();
 set_function_metatable();
+check_dependencies();
 load_libraries();
 init_global_state();
 read_version();