<commit_before>-- Copyright (c) 2011 Nokia Corporation.
-- Author: <NAME>
--
-- Licensed under LGPL version 2.1, see top level LICENSE file for details.

-- This script is executed by sb2d at startup, this
-- initializes the rule tree database (which is empty
-- but attached when this script is started)

session_dir = os.getenv("SBOX_SESSION_DIR")
debug_messages_enabled = sblib.debug_messages_enabled()

-- Create the "vperm" catalog
--	vperm::inodestats is the binary tree, initially empty,
--	but the entry must be present.
--	all counters must be present and zero in the beginning.
ruletree.catalog_set("vperm", "inodestats", 0)
ruletree.catalog_set("vperm", "num_active_inodestats",
	ruletree.new_uint32(0))

function do_file(filename)
	if (debug_messages_enabled) then
		sblib.log("debug", string.format("Loading '%s'", filename))
	end
	local 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

-- Load session-specific settings
do_file(session_dir .. "/sb2-session.conf")

target_root = sbox_target_root
if (not target_root or target_root == "") then
	target_root = "/"
end

tools_root = sbox_tools_root
if (tools_root == "") then
	tools_root = nil
end

tools = tools_root
if (not tools) then
	tools = "/"
end

if (tools == "/") then
        tools_prefix = ""
else
        tools_prefix = tools
end

-- Load session configuration, and add variables to ruletree.
do_file(session_dir .. "/sb2-session.conf")

ruletree.catalog_set("config", "sbox_cpu",
        ruletree.new_string(sbox_cpu))
ruletree.catalog_set("config", "sbox_uname_machine",
        ruletree.new_string(sbox_uname_machine))
ruletree.catalog_set("config", "sbox_emulate_sb1_bugs",
        ruletree.new_string(sbox_emulate_sb1_bugs))

-- Load exec config.
-- NOTE: At this point all conf_cputransparency_* variables
-- are still missing from exec_config.lua. Other variables
-- (conf_tools_*, conf_target_*, host_*) are there.
do_file(session_dir .. "/exec_config.lua")

-- Add exec config parameters to ruletree:
ruletree.catalog_set("config", "host_ld_preload", ruletree.new_string(host_ld_preload))
ruletree.catalog_set("config", "host_ld_library_path", ruletree.new_string(host_ld_library_path))

-- Build "all_modes" table. all_modes[1] will be name of default mode.
all_modes_str = os.getenv("SB2_ALL_MODES")
all_modes = {}

if (all_modes_str) then
	for m in string.gmatch(all_modes_str, "[^ ]*") do
		if m ~= "" then
			table.insert(all_modes, m)
			ruletree.catalog_set("MODES", m, 0)
		end
	end
end

ruletree.catalog_set("MODES", "#default", ruletree.new_string(all_modes[1]))

-- Exec preprocessing rules to ruletree:
do_file(session_dir .. "/lua_scripts/init_argvmods_rules.lua")

-- mode-spefic config to ruletree:
do_file(session_dir .. "/lua_scripts/init_modeconfig.lua")

-- Create rules based on "argvmods", e.g. rules for toolchain components etc.
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 mapping rules to ruletree:
do_file(session_dir .. "/lua_scripts/add_rules_to_rule_tree.lua")

-- and networking rules:
do_file(session_dir .. "/lua_scripts/init_net_modes.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)
<commit_msg>init.lua: Flush stdout and stderr<commit_after>-- Copyright (c) 2011 Nokia Corporation.
-- Author: <NAME>
--
-- Licensed under LGPL version 2.1, see top level LICENSE file for details.

-- This script is executed by sb2d at startup, this
-- initializes the rule tree database (which is empty
-- but attached when this script is started)

session_dir = os.getenv("SBOX_SESSION_DIR")
debug_messages_enabled = sblib.debug_messages_enabled()

-- Create the "vperm" catalog
--	vperm::inodestats is the binary tree, initially empty,
--	but the entry must be present.
--	all counters must be present and zero in the beginning.
ruletree.catalog_set("vperm", "inodestats", 0)
ruletree.catalog_set("vperm", "num_active_inodestats",
	ruletree.new_uint32(0))

function do_file(filename)
	if (debug_messages_enabled) then
		sblib.log("debug", string.format("Loading '%s'", filename))
	end
	local 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

-- Load session-specific settings
do_file(session_dir .. "/sb2-session.conf")

target_root = sbox_target_root
if (not target_root or target_root == "") then
	target_root = "/"
end

tools_root = sbox_tools_root
if (tools_root == "") then
	tools_root = nil
end

tools = tools_root
if (not tools) then
	tools = "/"
end

if (tools == "/") then
        tools_prefix = ""
else
        tools_prefix = tools
end

-- Load session configuration, and add variables to ruletree.
do_file(session_dir .. "/sb2-session.conf")

ruletree.catalog_set("config", "sbox_cpu",
        ruletree.new_string(sbox_cpu))
ruletree.catalog_set("config", "sbox_uname_machine",
        ruletree.new_string(sbox_uname_machine))
ruletree.catalog_set("config", "sbox_emulate_sb1_bugs",
        ruletree.new_string(sbox_emulate_sb1_bugs))

-- Load exec config.
-- NOTE: At this point all conf_cputransparency_* variables
-- are still missing from exec_config.lua. Other variables
-- (conf_tools_*, conf_target_*, host_*) are there.
do_file(session_dir .. "/exec_config.lua")

-- Add exec config parameters to ruletree:
ruletree.catalog_set("config", "host_ld_preload", ruletree.new_string(host_ld_preload))
ruletree.catalog_set("config", "host_ld_library_path", ruletree.new_string(host_ld_library_path))

-- Build "all_modes" table. all_modes[1] will be name of default mode.
all_modes_str = os.getenv("SB2_ALL_MODES")
all_modes = {}

if (all_modes_str) then
	for m in string.gmatch(all_modes_str, "[^ ]*") do
		if m ~= "" then
			table.insert(all_modes, m)
			ruletree.catalog_set("MODES", m, 0)
		end
	end
end

ruletree.catalog_set("MODES", "#default", ruletree.new_string(all_modes[1]))

-- Exec preprocessing rules to ruletree:
do_file(session_dir .. "/lua_scripts/init_argvmods_rules.lua")

-- mode-spefic config to ruletree:
do_file(session_dir .. "/lua_scripts/init_modeconfig.lua")

-- Create rules based on "argvmods", e.g. rules for toolchain components etc.
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 mapping rules to ruletree:
do_file(session_dir .. "/lua_scripts/add_rules_to_rule_tree.lua")

-- and networking rules:
do_file(session_dir .. "/lua_scripts/init_net_modes.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)

io.stdout:flush()
io.stderr:flush()
{'fraction_non_alphanumeric': 0.1238888888888889, 'fraction_numerical': 0.005833333333333334, 'mean_word_length': 4.430618401206637, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7109112', 'n_tokens_mistral': 2531, 'n_tokens_neox': 2456, 'n_words': 654}