Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create /usr/bin "autorules" via init.lua
- create_argvmods_usr_bin_rules.lua is now obsolete.
  • Loading branch information
lauri-aarnio committed Mar 18, 2012
1 parent 1fcf0f7 commit 1b7fb2f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
11 changes: 9 additions & 2 deletions lua_scripts/init_argvmods_rules.lua
Expand Up @@ -79,20 +79,25 @@ end
-- contents => variable name lookup table for the old-style table
-- FIXME: This is almost obsolete, can be removed after
-- create_argvmods_usr_bin_rules.lua has been replaced
-- (that functionality need to be moved to something which
-- is executed from init.lua after this file has been executed)
-- completely, and files are not anymore used to store rules
-- (currently all functionality from create_argvmods_usr_bin_rules.lua
-- has been moved to init_autogen_usr_bin_rules.lua, but the
-- algorithm is still the same => this code here is still needed.
-- A bigger code cleanup is needed.)
local table2tablename = {}
local table2tablename_n = 0

-- FIXME: This is almost obsolete, can be removed after
-- create_argvmods_usr_bin_rules.lua has been replaced.
-- (see comment above)
function clear_attr_list()
table2tablename = {}
table2tablename_n = 0
end

-- FIXME: This is almost obsolete, can be removed after
-- create_argvmods_usr_bin_rules.lua has been replaced.
-- (see comment above)
function prepare_stringlist(filehandle, name, stringlist)
if stringlist and #stringlist > 0 then
local x = stringlist_to_string(stringlist)
Expand All @@ -110,6 +115,7 @@ end

-- FIXME: This is almost obsolete, can be removed after
-- create_argvmods_usr_bin_rules.lua has been replaced.
-- (see comment above)
function find_stringlist_name(name, stringlist)
local stringlist_name = ""
if stringlist and #stringlist > 0 then
Expand Down Expand Up @@ -143,6 +149,7 @@ end
-- This function creates the old-style argvmods_*.lua files.
-- FIXME: This is almost obsolete, can be removed after
-- create_argvmods_usr_bin_rules.lua has been replaced.
-- (see comment above)
function argvmods_to_file(filename, num_argvmods_rules, argvmods_tbl)
argvmods_file = io.open(filename, "w")
if not argvmods_file then
Expand Down
6 changes: 6 additions & 0 deletions lua_scripts/init_autogen_usr_bin_rules.lua
Expand Up @@ -123,6 +123,12 @@ function create_mapping_rule_file(modename_in_ruletree)
end

for m_index,m_name in pairs(all_modes) do
local usr_bin_rules_flagfile = session_dir .. "/rules_auto/" ..
m_name .. ".create_usr_bin_rules"
local ff = io.open(usr_bin_rules_flagfile, "r")
if ff ~= nil then
ff:close()
create_mapping_rule_file(m_name)
end
end

44 changes: 21 additions & 23 deletions utils/sb2
Expand Up @@ -101,6 +101,7 @@ function exit_error()
# Parameters:
# - output file name
# - mapping mode name
# - name of "flag file"; created if /usr/bin/mapping rules need to be created
# - list of rule files (if specified by the -M option)
#
# Used during initialization stage 1 (while setting
Expand All @@ -109,9 +110,20 @@ function write_rules_to_session_dir()
{
output_file_name=$1
mapmode_name=$2
shift 2
usr_bin_rules_flagfile=$3
shift 3
input_files="$@"

# read mode-specific settings
CREATE_ARGVMODS_USR_BIN_RULES=""
if [ -f $SBOX_SESSION_DIR/modes/$mapmode_name/sb2rc ]; then
. $SBOX_SESSION_DIR/modes/$mapmode_name/sb2rc mode_settings
fi
if [ -n "$CREATE_ARGVMODS_USR_BIN_RULES" ]
then
touch $usr_bin_rules_flagfile
fi

cat >$output_file_name <<END
-- Rules for session $SBOX_SESSION_DIR
-- Automatically generated file, do not edit.
Expand Down Expand Up @@ -183,29 +195,17 @@ function locate_target_nsswitch_conf()
# Create some additional rules for the default mapping mode:
#
# Used during stage 3 (generation of automatic rules)
function create_argvmods_usr_bin_rules()
function add_auto_rules_to_mapping_rules()
{
default_rule=$1

# FIXME: this should process all modes, not just the default mode.
for ammf in $SBOX_SESSION_DIR/rules/$SBOX_MAPMODE.lua; do
amm_base=`basename $ammf .lua`

SBOX_ARGVMODS_USR_BIN_DEFAULT_RULE="$default_rule" \
__SB2_BINARYNAME="sb2:CreatingArgvmodsUsrBinRules" \
SBOX_SESSION_MODE=$amm_base sb2-monitor \
-L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \
execluafile \
$SBOX_SESSION_DIR/lua_scripts/create_argvmods_usr_bin_rules.lua \
>$SBOX_SESSION_DIR/rules/$amm_base.ARGVMODS
if [ $? != 0 ]; then
exit_error "Failed to create 'argvmods' for /usr/bin ($amm_base)"
fi
if [ -f $SBOX_SESSION_DIR/rules_auto/$amm_base.usr_bin.lua ]; then
# add the generated rules to the beginning of the rule file
cat $SBOX_SESSION_DIR/rules/$amm_base.ARGVMODS $ammf \
cat $SBOX_SESSION_DIR/rules_auto/$amm_base.usr_bin.lua $ammf \
>$SBOX_SESSION_DIR/rules/$amm_base.NEW
mv $SBOX_SESSION_DIR/rules/$amm_base.NEW $ammf
rm $SBOX_SESSION_DIR/rules/$amm_base.ARGVMODS
fi
done
}

Expand Down Expand Up @@ -1345,6 +1345,7 @@ function initialize_new_sb2_session()
mkdir $SBOX_SESSION_DIR/var/tmp
mkdir $SBOX_SESSION_DIR/proc
mkdir $SBOX_SESSION_DIR/rules
mkdir $SBOX_SESSION_DIR/rules_auto
mkdir $SBOX_SESSION_DIR/net_rules
mkdir $SBOX_SESSION_DIR/rev_rules
mkdir $SBOX_SESSION_DIR/exec_rules
Expand Down Expand Up @@ -1462,6 +1463,7 @@ function write_configfiles_and_rules_for_new_session()
for amm in $SB2_INTERNAL_MAPMODES; do
write_rules_to_session_dir \
$SBOX_SESSION_DIR/rules/$amm.lua $amm \
$SBOX_SESSION_DIR/rules_auto/$amm.create_usr_bin_rules \
$SBOX_SESSION_DIR/modes/$amm/fs_rules.lua
ln -s $SBOX_SESSION_DIR/modes/$amm/exec_rules.lua \
$SBOX_SESSION_DIR/exec_rules/$amm.lua
Expand Down Expand Up @@ -1840,12 +1842,8 @@ fi
# Now everything is ready, programs can be executed in SB2'ed environment.
# Make automatically generated rules, if needed:
if [ -z "$SBOX_JOIN_SESSION_FILE" ]; then
# if needed, create path mapping rules for toolchain components.
# this can only be done after "create_argvmods_rules" has been executed.
if [ -n "CREATE_ARGVMODS_USR_BIN_RULES" ]
then
create_argvmods_usr_bin_rules "$CREATE_ARGVMODS_USR_BIN_RULES"
fi
# if needed, add path mapping rules for toolchain components.
add_auto_rules_to_mapping_rules

#
# Create reverse mapping rules before starting the
Expand Down

0 comments on commit 1b7fb2f

Please sign in to comment.