summaryrefslogtreecommitdiff
path: root/tests/misc/chroot-fail.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/misc/chroot-fail.sh')
-rwxr-xr-xtests/misc/chroot-fail.sh54
1 files changed, 38 insertions, 16 deletions
diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh
index a84826fd..14499edd 100755
--- a/tests/misc/chroot-fail.sh
+++ b/tests/misc/chroot-fail.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# Verify that internal failure in chroot gives exact status.
-# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+# Copyright (C) 2009-2015 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,20 +29,42 @@ test $? = 125 || fail=1
chroot --- / true # unknown option
test $? = 125 || fail=1
-# Note chroot("/") succeeds for non-root users on some systems, but not all,
-# however we avoid the chroot() with "/" to have common behvavior.
-chroot / sh -c 'exit 2' # exit status propagation
-test $? = 2 || fail=1
-chroot / . # invalid command
-test $? = 126 || fail=1
-chroot / no_such # no such command
-test $? = 127 || fail=1
-
-# Ensure we don't chdir("/") when not changing root
-# to allow only changing user ids for a command.
-for dir in '/' '/.' '/../'; do
- curdir=$(chroot "$dir" env pwd) || fail=1
- test "$curdir" = '/' && fail=1
-done
+# chroot("/") succeeds for non-root users on some systems, but not all.
+if chroot / true ; then
+ can_chroot_root=1
+ chroot / sh -c 'exit 2' # exit status propagation
+ test $? = 2 || fail=1
+ chroot / . # invalid command
+ test $? = 126 || fail=1
+ chroot / no_such # no such command
+ test $? = 127 || fail=1
+else
+ test $? = 125 || fail=1
+ can_chroot_root=0
+fi
+
+# Ensure that --skip-chdir fails with a non-"/" argument.
+cat <<\EOF > exp || framework_failure_
+chroot: option --skip-chdir only permitted if NEWROOT is old '/'
+Try 'chroot --help' for more information.
+EOF
+chroot --skip-chdir . env pwd >out 2>err && fail=1
+compare /dev/null out || fail=1
+compare exp err || fail=1
+
+# Ensure we chdir("/") appropriately when NEWROOT is old "/".
+if test $can_chroot_root = 1; then
+ ln -s / isroot || framework_failure_
+ for dir in '/' '/.' '/../' isroot; do
+ # Verify that chroot(1) succeeds and performs chdir("/")
+ # (chroot(1) of coreutils-8.23 failed to run the latter).
+ curdir=$(chroot "$dir" env pwd) || fail=1
+ test "$curdir" = '/' || fail=1
+
+ # Test the "--skip-chdir" option.
+ curdir=$(chroot --skip-chdir "$dir" env pwd) || fail=1
+ test "$curdir" = '/' && fail=1
+ done
+fi
Exit $fail