summaryrefslogtreecommitdiff
path: root/lua_scripts
diff options
context:
space:
mode:
authorLauri Aarnio <Lauri.Aarnio@iki.fi>2008-09-17 16:24:28 +0300
committerLauri Leukkunen <lle@rahina.org>2008-09-27 00:02:42 +0300
commita0baecd97308a7b46a84c9b7bb44e455e72aee3b (patch)
tree95812310f5c8426e0a0e3215a84682ce678fc5ed /lua_scripts
parent0c01ae62acd58977b73304e424152a02eee883c9 (diff)
Cleanup: moved some globals and initialization code from mapping.lua to main.lua
Diffstat (limited to 'lua_scripts')
-rw-r--r--lua_scripts/main.lua24
-rw-r--r--lua_scripts/mapping.lua47
2 files changed, 25 insertions, 46 deletions
diff --git a/lua_scripts/main.lua b/lua_scripts/main.lua
index f017fca..2fcdd4f 100644
--- a/lua_scripts/main.lua
+++ b/lua_scripts/main.lua
@@ -2,19 +2,43 @@
-- Copyright (C) 2006, 2007 Lauri Leukkunen
-- Licensed under MIT license.
+-- This file is loaded by the libsb2.so preload library, from the
+-- constructor to initialize sb2's "Lua-side"
+
+debug = os.getenv("SBOX_MAPPING_DEBUG")
+debug_messages_enabled = sb.debug_messages_enabled()
function do_file(filename)
+ if (debug_messages_enabled) then
+ sb.log("debug", string.format("Loading '%s'", filename))
+ end
f, err = loadfile(filename)
if (f == nil) then
error("\nError while loading " .. filename .. ": \n"
.. err .. "\n")
+ -- "error()" never returns
else
f() -- execute the loaded chunk
end
end
+session_dir = os.getenv("SBOX_SESSION_DIR")
+
+-- SBOX_LUA_SCRIPTS environment variable controls where
+-- we look for the scriptlets defining the path mappings
lua_scripts = os.getenv("SBOX_LUA_SCRIPTS")
+compiler_root = os.getenv("SBOX_COMPILER_ROOT")
+if (not compiler_root) then
+ compiler_root = "/usr"
+end
+
+-- Load session-specific settings
+do_file(session_dir .. "/sb2-session.conf")
+do_file(session_dir .. "/exec_config.lua")
+
+-- Load mapping- and exec functions
do_file(lua_scripts .. "/mapping.lua")
do_file(lua_scripts .. "/argvenvp.lua")
+-- sb2 is ready for operation!
diff --git a/lua_scripts/mapping.lua b/lua_scripts/mapping.lua
index 6baaa2e..aaa14f4 100644
--- a/lua_scripts/mapping.lua
+++ b/lua_scripts/mapping.lua
@@ -2,24 +2,6 @@
-- Copyright (C) 2006, 2007 Lauri Leukkunen
-- Licensed under MIT license.
-
-compiler_root = os.getenv("SBOX_COMPILER_ROOT")
-if (not compiler_root) then
- compiler_root = "/usr"
-end
-
-debug = os.getenv("SBOX_MAPPING_DEBUG")
-
-debug_messages_enabled = sb.debug_messages_enabled()
-
--- SBOX_LUA_SCRIPTS environment variable controls where
--- we look for the scriptlets defining the path mappings
-
-rsdir = os.getenv("SBOX_LUA_SCRIPTS")
-if (rsdir == nil) then
- rsdir = "/scratchbox/lua_scripts"
-end
-
-- escape_string() prefixes the magic pattern matching
-- characters ^$()%.[]*+-?) with '%'
function escape_string(a)
@@ -78,31 +60,6 @@ function isprefix(a, b)
return string.sub(b, 1, string.len(a)) == a
end
-function load_and_execute_lua_script(filename)
- if (debug_messages_enabled) then
- sb.log("debug", string.format("Loading '%s'", filename))
- end
- f, err = loadfile(filename)
- if (f == nil) then
- error("\nError while loading " .. filename .. ": \n" ..
- err .. "\n")
- -- "error()" never returns
- end
-
- f() -- execute the loaded chunk
- if (debug_messages_enabled) then
- sb.log("debug", string.format("Loaded '%s'", filename))
- end
-end
-
-session_dir = os.getenv("SBOX_SESSION_DIR")
-
--- Load session-specific settings
-function load_session_settings()
- load_and_execute_lua_script(session_dir .. "/sb2-session.conf")
- load_and_execute_lua_script(session_dir .. "/exec_config.lua")
-end
-
-- Load mode-specific rules.
-- A mode file should define two variables:
-- 1. export_chains (array) contains mapping rule chains; this array
@@ -115,7 +72,7 @@ function load_and_check_rules()
export_chains = {}
exec_policy_chains = {}
- load_and_execute_lua_script(session_dir .. "/rules.lua")
+ do_file(session_dir .. "/rules.lua")
-- export_chains variable contains now the mapping rule chains
-- from the chunk
@@ -149,8 +106,6 @@ function load_and_check_rules()
end
end
-load_session_settings()
-
target_root = sbox_target_root
if (not target_root or target_root == "") then
target_root = "/"