diff --git a/lib/core.sh b/lib/core.sh index 3cd1daa..0a1d645 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -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(){ diff --git a/tests/test_core.sh b/tests/test_core.sh index 1f40693..baf17dd 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -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(){