Make the environment handling code detect errors and die if
authorZac Medico <zmedico@gentoo.org>
Mon, 26 Nov 2007 23:59:01 +0000 (23:59 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 26 Nov 2007 23:59:01 +0000 (23:59 -0000)
necessary. (trunk r8700)

svn path=/main/branches/2.1.2/; revision=8701

bin/ebuild.sh

index 9c4436697371978c45d2c7b0a5118151eb0c3c4d..8772219c6f97128844798f5e337f4ba01fe71bf6 100755 (executable)
@@ -1399,13 +1399,19 @@ filter_readonly_variables() {
 preprocess_ebuild_env() {
        filter_readonly_variables --filter-sandbox < "${T}"/environment \
                > "${T}"/environment.filtered
-       mv "${T}"/environment.filtered "${T}"/environment
+       if [ $? -ne 0 ] ; then
+               rm -f "${T}/environment.filtered"
+               return 1
+       fi
+       mv "${T}"/environment.filtered "${T}"/environment || return $?
+       rm -f "${T}/environment.success" || return $?
        # WARNING: Code inside this subshell should avoid making assumptions
        # about variables or functions after source "${T}"/environment has been
        # called. Any variables that need to be relied upon should already be
        # filtered out above.
        (
-               source "${T}"/environment
+               source "${T}/environment" && \
+                       touch "${T}/environment.success"
 
                # It's remotely possible that save_ebuild_env() has been overridden
                # by the above source command. To protect ourselves, we override it
@@ -1416,7 +1422,15 @@ preprocess_ebuild_env() {
                # Rely on save_ebuild_env() to filter out any remaining variables
                # and functions that could interfere with the current environment.
                save_ebuild_env
-       ) | filter_readonly_variables > "${T}"/environment
+       ) | filter_readonly_variables > "${T}/environment.filtered"
+       if [ -e "${T}/environment.success" ] ; then
+               rm "${T}/environment.success"
+               mv "${T}/environment.filtered" "${T}/environment"
+               return $?
+       else
+               rm -f "${T}/environment.filtered"
+       fi
+       return 1
 }
 
 # === === === === === === === === === === === === === === === === === ===
@@ -1529,8 +1543,9 @@ if ! hasq ${EBUILD_SH_ARGS} clean depend && \
        [ ! -f "${T}/environment" ] ; then
        bzip2 -dc "${EBUILD%/*}"/environment.bz2 > \
                "${T}/environment" 2> /dev/null
-       if [ -s "${T}/environment" ] ; then
-               preprocess_ebuild_env
+       if [ $? -eq 0 ] && [ -s "${T}/environment" ] ; then
+               preprocess_ebuild_env || \
+                       die "error processing '${EBUILD%/*}/environment.bz2'"
        else
                rm -f "${T}/environment"
        fi
@@ -1544,13 +1559,15 @@ elif ! hasq ${EBUILD_PHASE} depend && [ -f "${T}"/environment ] ; then
                # environment may have been saved by a different version of ebuild.sh,
                # so it can't trusted that it's been properly filtered. Therefore,
                # always preprocess the environment when ${PN} == portage.
-               preprocess_ebuild_env
+               preprocess_ebuild_env || \
+                       die "error processing environment"
        fi
        # Colon separated SANDBOX_* variables need to be cumulative.
        for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
                eval PORTAGE_${x}=\${!x}
        done
-       source "${T}"/environment
+       source "${T}"/environment || \
+               die "error sourcing environment"
        for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
                eval y=\${PORTAGE_${x}}
                if [ "${y}" != "${!x}" ] ; then