aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-02-10 18:40:31 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-02-10 18:40:31 +0000
commit189d4c6589da3d507e39a9f4a9b7530a97e9b7dc (patch)
treefe75cf788dd84d9fd620b853aa0d013478b4a78c
parent8fb457401d2f34ee96d144b602c7544098764e49 (diff)
downloadpaludis-189d4c6589da3d507e39a9f4a9b7530a97e9b7dc.tar.gz
paludis-189d4c6589da3d507e39a9f4a9b7530a97e9b7dc.tar.xz
Make environment filtering more robust against newlines in variables.
-rwxr-xr-xpaludis/repositories/gentoo/ebuild/ebuild.bash86
1 files changed, 50 insertions, 36 deletions
diff --git a/paludis/repositories/gentoo/ebuild/ebuild.bash b/paludis/repositories/gentoo/ebuild/ebuild.bash
index ec3b179..e5d53ca 100755
--- a/paludis/repositories/gentoo/ebuild/ebuild.bash
+++ b/paludis/repositories/gentoo/ebuild/ebuild.bash
@@ -169,6 +169,53 @@ done
[[ -z "${CBUILD}" ]] && export CBUILD="${CHOST}"
+ebuild_scrub_environment()
+{
+ local filters=(
+ -e '/^\(EU\|PP\|U\)ID=/d'
+ -e '/^BASH_\(ARGC\|ARGV\|LINENO\|SOURCE\|VERSINFO\)=/d'
+ -e '/^\(FUNCNAME\|GROUPS\|SHELLOPTS\)=/d'
+ -e '/^\(declare -x \)\?SANDBOX_ACTIVE=/d'
+ )
+
+ sed -i "${filters[@]}" "${1}"
+
+ (
+ source "${1}" || exit 1
+
+ unset -f diefunc perform_hook inherit
+
+ unset -v PATH ROOTPATH T PALUDIS_TMPDIR PALUDIS_EBUILD_LOG_LEVEL
+ unset -v PORTDIR FILESDIR ECLASSDIR DISTDIR PALUDIS_EBUILD_DIR
+ unset -v PALUDIS_EXTRA_DIE_MESSAGE PALUDIS_COMMAND PALUDIS_CLIENT
+
+ unset -v ${!PALUDIS_CMDLINE_*} PALUDIS_OPTIONS
+ unset -v ${!CONTRARIUS_CMDLINE_*} CONTRARIUS_OPTIONS
+ unset -v ${!GTKPALUDIS_CMDLINE_*} GTKPALUDIS_OPTIONS
+ unset -v ${!ADJUTRIX_CMDLINE_*} ADJUTRIX_OPTIONS
+ unset -v ${!QUALUDIS_CMDLINE_*} QUALUDIS_OPTIONS
+
+ unset -v PALUDIS_HOME PALUDIS_PID EBUILD_KILL_PID ROOT
+ unset -v CATEGORY PN PV P PVR PF ${!LD_*}
+
+ for v in ${!SANDBOX*}; do
+ [[ "${v}" == SANDBOX_ACTIVE ]] || unset "${v}"
+ done
+
+ for v in ${!BASH_*}; do
+ case "${v#BASH_}" in
+ ARGC|ARGV|LINENO|SOURCE|VERSINFO) ;;
+ *) unset -v "${v}"
+ esac
+ done
+
+ set >"${1}"
+ export -p >>"${1}"
+ ) || return $?
+
+ sed -i -e 's:^declare -rx:declare -x:' "${filters[@]}" "${1}"
+}
+
ebuild_load_ebuild()
{
if [[ -n "${PALUDIS_LOAD_ENVIRONMENT}" ]] ; then
@@ -176,7 +223,7 @@ ebuild_load_ebuild()
|| die "You need to create PALUDIS_TMPDIR (${PALUDIS_TMPDIR})."
local save_PALUDIS_EXTRA_DIE_MESSAGE="${PALUDIS_EXTRA_DIE_MESSAGE}"
- local real_PALUDIS_EXTRA_DIE_MESSAGE="
+ export PALUDIS_EXTRA_DIE_MESSAGE="
!!! Could not extract the saved environment file. This is usually
!!! caused by a broken environment.bz2 that was generated by an old
!!! Portage version. The file that needs repairing is:
@@ -186,45 +233,12 @@ ebuild_load_ebuild()
!!! should get an error that give you a rough idea of where the
!!! problem lies.
"
- export PALUDIS_EXTRA_DIE_MESSAGE="${real_PALUDIS_EXTRA_DIE_MESSAGE}"
bunzip2 < "${PALUDIS_LOAD_ENVIRONMENT}" > ${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF} \
|| die "Can't extract ${PALUDIS_LOAD_ENVIRONMENT}"
- sed -i \
- -e '/^diefunc ()/,/^}/d' \
- -e '/^perform_hook ()/,/^}/d' \
- -e '/^inherit ()/,/^}/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?ROOTPATH=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PATH=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?T=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_TMPDIR=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_EBUILD_LOG_LEVEL=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PORTDIR=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?FILESDIR=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?ECLASSDIR=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?DISTDIR=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_EBUILD_DIR=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_COMMAND=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_CLIENT=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?\(PALUDIS\|CONTRARIUS\|GTKPALUDIS\)_CMDLINE_.*=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?\(ADJUTRIX\|QUALUDIS\)_CMDLINE_.*=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?\(PALUDIS\|CONTRARIUS\|GTKPALUDIS\)_OPTIONS=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?\(ADJUTRIX\|QUALUDIS\)_OPTIONS=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_HOME=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?PALUDIS_PID=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?EBUILD_KILL_PID=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?ROOT=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?SANDBOX/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?BASH_/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?SHELLOPTS/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?..\?ID=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?LD_/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?CATEGORY=/d' \
- -e '/^\(declare \(-[^ ]\+ \)\?\)\?\(PN\|PV\|P\|PVR\|PF\)=/d' \
- "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}"
-
- export PALUDIS_EXTRA_DIE_MESSAGE="${real_PALUDIS_EXTRA_DIE_MESSAGE}"
+ ebuild_scrub_environment "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}" \
+ || die "Can't load saved environment for cleaning"
echo source "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}" 1>&2
source "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}" \