diff --git a/lua_scripts/init_argvmods_rules.lua b/lua_scripts/init_argvmods_rules.lua index a3abb422..68e63e54 100644 --- a/lua_scripts/init_argvmods_rules.lua +++ b/lua_scripts/init_argvmods_rules.lua @@ -79,13 +79,17 @@ 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 @@ -93,6 +97,7 @@ 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) @@ -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 @@ -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 diff --git a/lua_scripts/init_autogen_usr_bin_rules.lua b/lua_scripts/init_autogen_usr_bin_rules.lua index 71e32d0c..e92fe0f1 100644 --- a/lua_scripts/init_autogen_usr_bin_rules.lua +++ b/lua_scripts/init_autogen_usr_bin_rules.lua @@ -123,6 +123,12 @@ function create_mapping_rule_file(modename_in_ruletree) end for m_index,m_name in pairs(all_modes) do - create_mapping_rule_file(m_name) + 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 diff --git a/utils/sb2 b/utils/sb2 index 57d25949..d3ef7f52 100755 --- a/utils/sb2 +++ b/utils/sb2 @@ -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 @@ -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 <$SBOX_SESSION_DIR/rules/$amm_base.ARGVMODS - if [ $? != 0 ]; then - exit_error "Failed to create 'argvmods' for /usr/bin ($amm_base)" + 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_auto/$amm_base.usr_bin.lua $ammf \ + >$SBOX_SESSION_DIR/rules/$amm_base.NEW + mv $SBOX_SESSION_DIR/rules/$amm_base.NEW $ammf fi - # add the generated rules to the beginning of the rule file - cat $SBOX_SESSION_DIR/rules/$amm_base.ARGVMODS $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 done } @@ -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 @@ -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 @@ -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