bug#81502: [PATCH] tests: chgrp: test --preserve-root within a chroot en
From:
Pádraig Brady
Subject:
bug#81502: [PATCH] tests: chgrp: test --preserve-root within a chroot env
Date:
Mon, 27 Jul 2026 12:12:38 +0100
User-agent:
Mozilla Thunderbird Beta
On 27/07/2026 04:03, zuohsh wrote:
* tests/local.mk: reference the new test.
* tests/chgrp/preserve-root.sh: the new file.
---
+print_ver_ chgrp
+require_root_
OK so you're proposing this as root
to support chroot, rather than have chgrp operate as root?
In that case I think chroot --userspec=... would be safer.
Also a general point is that chown and chgrp are essentially the same,
so it would be good to test both.
Actually we already have an existing
https://github.com/coreutils/coreutils/blob/master/tests/chown/preserve-root.sh
so it would be good to mention a quick summary of what extra this tests.
+
+# Create a safe chroot environment for testing
+chroot_dir="$PWD/chroot_test"
+mkdir -p "$chroot_dir"/{bin,lib,lib64,etc,dev,tmp} || framework_failure_
+# Copy essential files for chroot to work
+cp /bin/sh "$chroot_dir/bin/" 2>/dev/null || \
+ cp /usr/bin/sh "$chroot_dir/bin/sh" 2>/dev/null || framework_failure_
+
+# Copy required libraries if any
+ldd $chroot_dir/bin/sh 2>/dev/null | grep -o '/lib[^ ]*' | while read lib; do
+ test -f "$lib" && cp "$lib" "$chroot_dir/lib/" 2>/dev/null || true
+done
+
+pwd
+# Copy chgrp binary to chroot
+cp ${srcdir}/src/chgrp "$chroot_dir/bin/chgrp" || framework_failure_
+
+# Copy chgrp's required libraries
+ldd $chroot_dir/bin/chgrp | grep -o '/lib[^ ]*' | while read lib; do
+ test -f "$lib" && cp "$lib" "$chroot_dir/lib/" 2>/dev/null || true
+ test -f "$lib" && cp "$lib" "$chroot_dir/lib64/" 2>/dev/null || true
+done