Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Execute add_rules_to_rule_tree.lua from init.lua
- it was called from the "sb2" script.
- From now on, all rule tree initialization actions are
  initiated from init.lua (which is executed by sb2d after startup).
  • Loading branch information
lauri-aarnio committed Mar 18, 2012
1 parent 2628373 commit aee5e70
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 63 deletions.
80 changes: 51 additions & 29 deletions lua_scripts/add_rules_to_rule_tree.lua
Expand Up @@ -3,15 +3,9 @@
--
-- Licensed under MIT license

-- This script is executed when SB2 session is created,
-- to load FS mapping rules to the "rule tree" database.

if not mapping_engine_loaded then
do_file(session_dir .. "/lua_scripts/mapping.lua")
end
if not exec_engine_loaded then
do_file(session_dir .. "/lua_scripts/argvenvp.lua")
end
-- This script is executed when SB2 session is created
-- (from init.lua) to load FS mapping rules to the rule
-- tree database.

-- Rule tree constants. These must match the #defines in <rule_tree.h>
local RULE_SELECTOR_PATH = 101
Expand Down Expand Up @@ -297,7 +291,7 @@ function add_all_exec_policies(modename_in_ruletree)
for i = 1, table.maxn(all_exec_policies) do
local ep_name = all_exec_policies[i].name
if ep_name then
sb.log("debug", "Adding Exec policy "..ep_name)
sblib.log("debug", "Adding Exec policy "..ep_name)
for key,val in pairs(all_exec_policies[i]) do
local required_type = valid_keywords_in_exec_policy[key]
local t = type(val)
Expand Down Expand Up @@ -330,26 +324,54 @@ end

-- ================= Main =================

ruletree.attach_ruletree()
for m_index,m_name in pairs(all_modes) do
local modename_in_ruletree = m_name

local forced_modename = sb.get_forced_mapmode()
if forced_modename then
modename_in_ruletree = forced_modename
else
print("ERROR: forced_modename = nil")
os.exit(12)
end
print("sbox_mapmode = "..sbox_mapmode)
print("active_mapmode = "..active_mapmode)
print("modename_in_ruletree = "..modename_in_ruletree)
local autorule_file_path = session_dir .. "/rules_auto/" .. m_name .. ".usr_bin.lua"
local rule_file_path = session_dir .. "/rules/" .. m_name .. ".lua"
local rev_rule_filename = session_dir .. "/rev_rules/" ..
m_name .. ".lua"
local exec_rule_file_path = session_dir .. "/exec_rules/" ..
m_name .. ".lua"


-- FS rulefile will set these:
rule_file_interface_version = nil
fs_mapping_rules = nil

-- Exec rulefile will set:
all_exec_policies = nil

local ri
ri = add_list_of_rules(fs_mapping_rules, true) -- add ordinary (forward) rules
print("-- Added ruleset fwd rules")
ruletree.catalog_set("fs_rules", modename_in_ruletree, ri)
-- rulefiles expect to see this:
active_mapmode = m_name

ri = add_list_of_rules(reverse_fs_mapping_rules, true) -- add reverse rules
print("-- Added ruleset rev.rules")
ruletree.catalog_set("rev_rules", modename_in_ruletree, ri)
-- Reload "constants", just to be sure:
do_file(session_dir .. "/lua_scripts/rule_constants.lua")

add_all_exec_policies(modename_in_ruletree)
-- Main config file:
do_file(session_dir .. "/share/scratchbox2/modes/"..modename_in_ruletree.."/config.lua")

-- Load FS rules for this mode:
do_file(autorule_file_path)
do_file(rule_file_path)
do_file(rev_rule_filename)

-- Load exec policies:
do_file(session_dir .. "/exec_config.lua")
do_file(exec_rule_file_path)

print("sbox_mapmode = "..sbox_mapmode)
print("active_mapmode = "..active_mapmode)
print("modename_in_ruletree = "..modename_in_ruletree)

local ri
ri = add_list_of_rules(fs_mapping_rules, true) -- add ordinary (forward) rules
print("-- Added ruleset fwd rules")
ruletree.catalog_set("fs_rules", modename_in_ruletree, ri)

ri = add_list_of_rules(reverse_fs_mapping_rules, true) -- add reverse rules
print("-- Added ruleset rev.rules")
ruletree.catalog_set("rev_rules", modename_in_ruletree, ri)

add_all_exec_policies(modename_in_ruletree)
end
8 changes: 8 additions & 0 deletions lua_scripts/init.lua
Expand Up @@ -103,3 +103,11 @@ do_file(session_dir .. "/lua_scripts/init_autogen_usr_bin_rules.lua")
-- Create reverse mapping rules.
do_file(session_dir .. "/lua_scripts/create_reverse_rules.lua")

-- Now add all rules to ruletree:
do_file(session_dir .. "/lua_scripts/add_rules_to_rule_tree.lua")

-- Done. conf_cputransparency_* are still missing from the rule tree,
-- but those can't be added yet (see the "sb2" script - it finds
-- values for those variables only after sb2d has executed this
-- script)

38 changes: 4 additions & 34 deletions utils/sb2
Expand Up @@ -186,32 +186,6 @@ function add_auto_rules_to_mapping_rules()
done
}

# Used during stage 3 (generation of automatic rules)
function add_rules_to_rule_tree_db()
{
mkdir $SBOX_SESSION_DIR/ruletree.logs

for ammf in $SBOX_SESSION_DIR/rules/*.lua; do
amm_base=`basename $ammf .lua`

__SB2_BINARYNAME="sb2:Rules2RuleTree" \
SBOX_SESSION_MODE=$amm_base sb2-monitor \
-L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \
execluafile \
$SBOX_SESSION_DIR/lua_scripts/add_rules_to_rule_tree.lua \
>$SBOX_SESSION_DIR/ruletree.logs/$amm_base.out \
2>$SBOX_SESSION_DIR/ruletree.logs/$amm_base.err
add_rules_exit_status=$?
if [ -s $SBOX_SESSION_DIR/ruletree.logs/$amm_base.err ]; then
cat $SBOX_SESSION_DIR/ruletree.logs/$amm_base.err
exit_error "Faulty rule file ($amm_base)"
fi
if [ $add_rules_exit_status != 0 ]; then
exit_error "Failed to add rules from $amm_base to rule tree"
fi
done
}

#
# Used during initialization stage 1 (while setting
# up the environment, which can't be used yet)
Expand Down Expand Up @@ -1799,21 +1773,17 @@ fi
# END OF INITIALIZATION STAGE 2.

# ------------
# STAGE 3, GENERATION OF AUTOMATIC RULES, begins:
# STAGE 3, GENERATION OF AUTOMATIC RULES:
#
# Now everything is ready, programs can be executed in SB2'ed environment.
# Make automatically generated rules, if needed:
# This is easy now. All rule files are nowadays created by sb2d,
# from init.lua. Just one additional step is needed, if
# mapping method == "Lua" is still used:
if [ -z "$SBOX_JOIN_SESSION_FILE" ]; then
# if needed, add path mapping rules for toolchain components
# to the rule files which may be loaded at runtime
# (if Lua mapping method is used)
add_auto_rules_to_mapping_rules

#
# Create the "rule tree" file for the C mapping
# engine:
add_rules_to_rule_tree_db

# session setup ok, stamp it.
touch $SBOX_SESSION_DIR/.session_stamp
else
Expand Down

0 comments on commit aee5e70

Please sign in to comment.