net.server_select: When an SSL handshake is connected, if there is pending data to...
[prosody.git] / prosody
diff --git a/prosody b/prosody
index 9a88eac0b227e65406608276a3f4e861fe78ef94..aab803c5b8c71c16ce616a7b0ccb09ef617f4318 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"
@@ -86,6 +83,7 @@ function read_config()
                        break;
                end
        end
+       prosody.config_file = filename
        local ok, level, err = config.load(filename);
        if not ok then
                print("\n");
@@ -115,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"
@@ -149,7 +153,12 @@ function sandbox_require()
        local _real_require = require;
        if not getfenv then
                -- 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
+               function getfenv(f)
+                       local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
+                       if name == "_ENV" then
+                               return env;
+                       end
+               end
        end
        function require(...)
                local curr_env = getfenv(2);
@@ -240,7 +249,7 @@ function init_global_state()
        function prosody.reload_config()
                log("info", "Reloading configuration file");
                prosody.events.fire_event("reloading-config");
-               local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua");
+               local ok, level, err = config.load(prosody.config_file);
                if not ok then
                        if level == "parser" then
                                log("error", "There was an error parsing the configuration file: %s", tostring(err));
@@ -264,12 +273,6 @@ function init_global_state()
                prosody.events.fire_event("server-stopping", {reason = reason});
                server.setquitting(true);
        end
-
-       -- Load SSL settings from config, and create a ctx table
-       local certmanager = require "core.certmanager";
-       local global_ssl_ctx = certmanager.create_context("*", "server");
-       prosody.global_ssl_ctx = global_ssl_ctx;
-
 end
 
 function read_version()
@@ -387,6 +390,7 @@ init_logging();
 sanity_check();
 sandbox_require();
 set_function_metatable();
+check_dependencies();
 load_libraries();
 init_global_state();
 read_version();