Skip to content

Commit e676e83

Browse files
Ioa1mgree
andauthored
ensure environment in try is similar to host (#153) (#207)
Co-authored-by: Michael Greenberg <michael@greenberg.science>
1 parent 7d9d59d commit e676e83

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ TRY_TEST_PROG([curl])
224224
TRY_TEST_PROG([diff])
225225
TRY_TEST_PROG([touch])
226226
TRY_TEST_PROG([gunzip])
227+
TRY_TEST_PROG([realpath])
227228

228229
if test "$missing_test_programs" -ne 0
229230
then

test/check_env.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}"
4+
TRY="$TRY_TOP/try"
5+
6+
cleanup() {
7+
8+
if [ -f "$expected" ]; then
9+
rm "$expected"
10+
fi
11+
12+
if [ -f "$out" ]; then
13+
rm "$out"
14+
fi
15+
16+
}
17+
18+
out="$(mktemp)"
19+
expected="$(mktemp)"
20+
21+
echo "$PWD $OLDPWD" >"$expected"
22+
23+
# shellcheck disable=SC2016
24+
"$TRY" 'echo "$PWD $OLDPWD"' >"$out" || exit 1
25+
26+
if ! diff -q "$expected" "$out"; then
27+
exit 2
28+
fi
29+
30+
rm "$out"
31+
rm "$expected"
32+
33+
trap 'cleanup' EXIT

test/check_shell.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ check_case() {
2424
expected="$(mktemp)"
2525
out="$(mktemp)"
2626
echo "$expected_output" >"$expected"
27-
TRY_SHELL="$try_shell" SHELL="$shell" "$TRY" "echo \"\$TRY_SHELL\"" >"$out" || exit 1
27+
TRY_SHELL="$try_shell" SHELL="$shell" "$TRY" 'realpath /proc/$$/exe' >"$out" || exit "$case"
2828

29-
if ! diff -q "$expected" "$out"; then
29+
if ! diff "$expected" "$out"; then
3030
exit "$case"
3131
fi
3232

@@ -37,6 +37,6 @@ check_case() {
3737

3838
trap 'cleanup' EXIT
3939

40-
check_case "/bin/bash" "/bin/sh" "/bin/bash" "1"
40+
check_case "/bin/bash" "/bin/sh" "$(realpath "/bin/bash")" "1"
4141

42-
check_case "" "/bin/bash" "/bin/bash" "2"
42+
check_case "" "/bin/bash" "$(realpath "/bin/bash")" "2"

try

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,15 @@ EOF
282282
cat >"$chroot_executable" <<EOF
283283
#!/bin/sh
284284
285-
unset START_DIR SANDBOX_DIR UNION_HELPER DIRS_AND_MOUNTS TRY_EXIT_STATUS
285+
unset START_DIR SANDBOX_DIR UNION_HELPER DIRS_AND_MOUNTS TRY_EXIT_STATUS TRY_COMMAND TRY_SHELL UPDATED_DIRS_AND_MOUNTS
286286
unset script_to_execute chroot_executable try_mount_log
287287
288288
mount -t proc proc /proc &&
289289
ln -s /proc/self/fd/0 /dev/stdin &&
290290
ln -s /proc/self/fd/1 /dev/stdout &&
291291
ln -s /proc/self/fd/2 /dev/stderr &&
292292
cd "$START_DIR" &&
293-
. "$script_to_execute"
293+
OLDPWD=$OLDPWD . "$script_to_execute"
294294
EOF
295295

296296
echo "$@" >"$script_to_execute"

0 commit comments

Comments
 (0)