Skip to content

Commit

Permalink
Substitute commands only if FAKECHROOT_CMD_ORIG is not set. Unset it …
Browse files Browse the repository at this point in the history
…if is empty.
  • Loading branch information
dex4er committed Dec 2, 2011
1 parent 904788c commit 711cefa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion man/fakechroot.pod
Expand Up @@ -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<FAKECHROOT_BASE_ORIG> variable is not set currently.
C<FAKECHROOT_CMD_ORIG> variable is not set currently.

=item B<LD_LIBRARY_PATH>, B<LD_PRELOAD>

Expand Down
13 changes: 8 additions & 5 deletions scripts/chroot.fakechroot.sh
Expand Up @@ -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
Expand All @@ -50,18 +53,18 @@ 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}"
paths="${paths#:}"
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 $?
7 changes: 6 additions & 1 deletion src/execve.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 711cefa

Please sign in to comment.