Refactor the chroot script

This commit is contained in:
Filippo Squillace 2015-06-28 12:30:22 +00:00
parent 98a1ef5bf0
commit 45814d65a5
2 changed files with 5 additions and 13 deletions

View file

@ -200,21 +200,13 @@ function run_env_as_root(){
local main_cmd="${SH[@]}"
[ "$1" != "" ] && main_cmd="$(insert_quotes_on_spaces "$@")"
# With chown the ownership of the files is assigned to the real user
trap - QUIT EXIT ABRT KILL TERM INT
trap "[ -z $uid ] || chown_cmd -R ${uid} ${JUNEST_HOME}; rm_cmd -r ${JUNEST_HOME}/etc/mtab" EXIT QUIT ABRT KILL TERM INT
trap "[ -z $uid ] || chown_cmd -R ${uid} ${JUNEST_HOME}; rm_cmd -f ${JUNEST_HOME}/etc/mtab" EXIT QUIT ABRT KILL TERM INT
[ ! -e ${JUNEST_HOME}/etc/mtab ] && ln_cmd -s /proc/self/mounts ${JUNEST_HOME}/etc/mtab
JUNEST_ENV=1 chroot_cmd "$JUNEST_HOME" "${SH[@]}" "-c" "${main_cmd}"
local ret=$?
# The ownership of the files is assigned to the real user
[ -z $uid ] || chown_cmd -R ${uid} ${JUNEST_HOME}
[ -e ${JUNEST_HOME}/etc/mtab ] && rm_cmd -r ${JUNEST_HOME}/etc/mtab
trap - QUIT EXIT ABRT KILL TERM INT
return $?
}
function _run_env_with_proot(){

View file

@ -188,6 +188,8 @@ function test_run_env_as_root(){
# test that normal user has ownership of the files created by root
run_env_as_root touch /a_root_file
# This ensure that the trap will be executed
kill -TERM $$
local output=$(run_env_as_root stat -c '%u' /a_root_file)
assertEquals "$UID" "$output"
@ -214,8 +216,6 @@ function test_run_env_as_classic_root(){
assertEquals "/" "$output"
run_env_as_root [ -e /run/lock ] 2> /dev/null
assertEquals 0 $?
run_env_as_root [ -e $HOME ] 2> /dev/null
assertEquals 0 $?
}
function test_run_env_as_junest_root(){
@ -232,7 +232,7 @@ function test_run_env_as_junest_root(){
run_env_as_root [ -e /run/lock ] 2> /dev/null
assertEquals 0 $?
run_env_as_root [ -e $HOME ] 2> /dev/null
assertEquals 0 $?
assertEquals 1 $?
}
function test_run_env_as_user(){