27 |
27 |
28 -- Substitute ~ with path to home directory in data path |
28 -- Substitute ~ with path to home directory in data path |
29 if CFG_DATADIR then |
29 if CFG_DATADIR then |
30 if os.getenv("HOME") then |
30 if os.getenv("HOME") then |
31 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
31 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
32 end |
|
33 end |
|
34 |
|
35 -- Initialize logging |
|
36 require "core.loggingmanager" |
|
37 |
|
38 -- Check runtime dependencies |
|
39 if not require "util.dependencies".check_dependencies() then |
|
40 os.exit(1); |
|
41 end |
|
42 |
|
43 -- Replace require() with one that doesn't pollute _G, required |
|
44 -- for neat sandboxing of modules |
|
45 do |
|
46 local _realG = _G; |
|
47 local _real_require = require; |
|
48 function require(...) |
|
49 local curr_env = getfenv(2); |
|
50 local curr_env_mt = getmetatable(getfenv(2)); |
|
51 local _realG_mt = getmetatable(_realG); |
|
52 if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then |
|
53 local old_newindex |
|
54 old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env; |
|
55 local ret = _real_require(...); |
|
56 _realG_mt.__newindex = old_newindex; |
|
57 return ret; |
|
58 end |
|
59 return _real_require(...); |
|
60 end |
32 end |
61 end |
33 end |
62 |
34 |
63 -- Load the config-parsing module |
35 -- Load the config-parsing module |
64 config = require "core.configmanager" |
36 config = require "core.configmanager" |
116 |
88 |
117 function load_libraries() |
89 function load_libraries() |
118 -- Load socket framework |
90 -- Load socket framework |
119 server = require "net.server" |
91 server = require "net.server" |
120 end |
92 end |
|
93 |
|
94 function init_logging() |
|
95 -- Initialize logging |
|
96 require "core.loggingmanager" |
|
97 end |
|
98 |
|
99 function check_dependencies() |
|
100 -- Check runtime dependencies |
|
101 if not require "util.dependencies".check_dependencies() then |
|
102 os.exit(1); |
|
103 end |
|
104 end |
|
105 |
|
106 function sandbox_require() |
|
107 -- Replace require() with one that doesn't pollute _G, required |
|
108 -- for neat sandboxing of modules |
|
109 local _realG = _G; |
|
110 local _real_require = require; |
|
111 function require(...) |
|
112 local curr_env = getfenv(2); |
|
113 local curr_env_mt = getmetatable(getfenv(2)); |
|
114 local _realG_mt = getmetatable(_realG); |
|
115 if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then |
|
116 local old_newindex |
|
117 old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env; |
|
118 local ret = _real_require(...); |
|
119 _realG_mt.__newindex = old_newindex; |
|
120 return ret; |
|
121 end |
|
122 return _real_require(...); |
|
123 end |
|
124 end |
121 |
125 |
122 function init_global_state() |
126 function init_global_state() |
123 bare_sessions = {}; |
127 bare_sessions = {}; |
124 full_sessions = {}; |
128 full_sessions = {}; |
125 hosts = {}; |
129 hosts = {}; |
405 |
409 |
406 server.setquitting(true); |
410 server.setquitting(true); |
407 end |
411 end |
408 |
412 |
409 -- Are you ready? :) |
413 -- Are you ready? :) |
|
414 -- These actions are in a strict order, as many depend on |
|
415 -- previous steps to have already been performed |
410 read_config(); |
416 read_config(); |
|
417 init_logging(); |
|
418 check_dependencies(); |
|
419 sandbox_require(); |
411 load_libraries(); |
420 load_libraries(); |
412 init_global_state(); |
421 init_global_state(); |
413 read_version(); |
422 read_version(); |
414 log("info", "Hello and welcome to Prosody version %s", prosody.version); |
423 log("info", "Hello and welcome to Prosody version %s", prosody.version); |
415 load_secondary_libraries(); |
424 load_secondary_libraries(); |