From 711cefa8ee63c5e1c0cb8feaf7376ba74e9de522 Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Fri, 2 Dec 2011 02:24:28 +0100 Subject: [PATCH] Substitute commands only if FAKECHROOT_CMD_ORIG is not set. Unset it if is empty. --- man/fakechroot.pod | 2 +- scripts/chroot.fakechroot.sh | 13 ++++++++----- src/execve.c | 7 ++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/man/fakechroot.pod b/man/fakechroot.pod index 7b4e511c..86450e7f 100644 --- a/man/fakechroot.pod +++ b/man/fakechroot.pod @@ -263,7 +263,7 @@ It is suggested to substitute at least: to make debootstrap(8) working correctly. To prevent some looping, the command substitution is done only if -C variable is not set currently. +C variable is not set currently. =item B, B diff --git a/scripts/chroot.fakechroot.sh b/scripts/chroot.fakechroot.sh index 56306163..b5230619 100644 --- a/scripts/chroot.fakechroot.sh +++ b/scripts/chroot.fakechroot.sh @@ -29,8 +29,11 @@ load_ldsoconf () { done } -chroot=${FAKECHROOT_CMD_ORIG:-chroot} -unset FAKECHROOT_CMD_ORIG +chroot="${FAKECHROOT_CMD_ORIG:-chroot}" +FAKECHROOT_CMD_ORIG= + +base="$FAKECHROOT_BASE_ORIG" +unset FAKECHROOT_BASE_ORIG for opt in "$@"; do case "$opt" in @@ -50,12 +53,12 @@ if [ -n "$newroot" ]; then # append newroot to each directory from original LD_LIBRARY_PATH IFS_bak="$IFS" IFS=: for d in $LD_LIBRARY_PATH; do - paths="${paths:+$paths:}$FAKECHROOT_BASE_ORIG$newroot/${d#/}" + paths="${paths:+$paths:}$base$newroot/${d#/}" done IFS="$IFS_bak" # append newroot to each directory from new /etc/ld.so.conf - paths_ldsoconf=`load_ldsoconf "/etc/ld.so.conf" "$newroot" | while read line; do printf ":%s%s" "$FAKECHROOT_BASE_ORIG" "$line"; done` + paths_ldsoconf=`load_ldsoconf "/etc/ld.so.conf" "$newroot" | while read line; do printf ":%s%s" "$base" "$line"; done` paths_ldsoconf="${paths_ldsoconf#:}" paths="$paths${paths_ldsoconf:+:$paths_ldsoconf}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" @@ -63,5 +66,5 @@ if [ -n "$newroot" ]; then fi # call real chroot -env LD_LIBRARY_PATH="$paths" FAKECHROOT_BASE_ORIG=$FAKECHROOT_BASE_ORIG FAKECHROOT_BASE=$FAKECHROOT_BASE_ORIG "$chroot" "$@" +env LD_LIBRARY_PATH="$paths" FAKECHROOT_BASE="$base" "$chroot" "$@" exit $? diff --git a/src/execve.c b/src/execve.c index 048567c2..5e0e7618 100644 --- a/src/execve.c +++ b/src/execve.c @@ -79,6 +79,7 @@ wrapper(execve, int, (const char * filename, char * const argv [], char * const const char **newargv = alloca(argv_max * sizeof (const char *)); char **newenvp, **ep; char *key, *env; + char *cmdorig; char tmp[FAKECHROOT_PATH_MAX]; char substfilename[FAKECHROOT_PATH_MAX]; char newfilename[FAKECHROOT_PATH_MAX]; @@ -106,8 +107,12 @@ wrapper(execve, int, (const char * filename, char * const argv [], char * const strncpy(argv0, filename, FAKECHROOT_PATH_MAX); - if (!getenv("FAKECHROOT_BASE_ORIG")) + /* Substitute command only if FAKECHROOT_CMD_ORIG is not set. Unset variable if it is empty. */ + cmdorig = getenv("FAKECHROOT_CMD_ORIG"); + if (cmdorig == NULL) do_cmd_subst = try_cmd_subst(getenv("FAKECHROOT_CMD_SUBST"), argv0, substfilename); + else if (!*cmdorig) + unsetenv("FAKECHROOT_CMD_ORIG"); /* Scan envp and check its size */ sizeenvp = 0;