]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: use tar --no-same-owner for sysfs dump extraction
authorKarel Zak <kzak@redhat.com>
Thu, 28 May 2026 09:05:55 +0000 (11:05 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 28 May 2026 09:10:18 +0000 (11:10 +0200)
Use --no-same-owner when extracting sysfs dump tarballs so that
extracted files are owned by the current user rather than preserving
the original (often root) ownership from the archive.

This allows chmem tests to run without root since they only operate
on a local sysfs dump via --sysroot. The valid_zones file (0444 in
real sysfs) needs an explicit chmod u+w before the test can write
to it. Apply --no-same-owner to lsblk, lscpu, lsmem, and hardlink
tests for consistency.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/ts/chmem/aarch64_16k_16g
tests/ts/chmem/x86_64_16g
tests/ts/hardlink/options
tests/ts/lsblk/lsblk
tests/ts/lscpu/lscpu
tests/ts/lsmem/lsmem

index ad201e314c77055b17ded503ade2addf5d5366a0..da075adf8d30ad2eeece993b432baf6f2e5f7d63 100755 (executable)
@@ -20,8 +20,6 @@ TS_DESC="aarch64_16k_16g"
 . "$TS_TOPDIR/functions.sh"
 ts_init "$*"
 
-ts_skip_nonroot
-
 ts_check_test_command "$TS_CMD_CHMEM"
 ts_check_test_command "$TS_CMD_LSMEM"
 ts_check_prog "bzip2"
@@ -34,7 +32,7 @@ DUMP_FILENAME="$TS_SELF/sysfs-dumps/$DUMP_NAME.tar.bz2"
 DUMP_DIR="$TS_OUTDIR/sysfs-dumps"
 
 mkdir -p "$DUMP_DIR"
-tar -C "$DUMP_DIR" -jxf "$DUMP_FILENAME"
+tar --no-same-owner -C "$DUMP_DIR" -jxf "$DUMP_FILENAME"
 
 do_chmem() {
         "$TS_CMD_CHMEM" --sysroot "${DUMP_DIR}/${DUMP_NAME}" "${@}" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
@@ -76,6 +74,7 @@ mem_block="memory${index}"
 
 # We need to enable the "Movable" zone on this block first
 # otherwise chmem will complain about a zone mismatch
+chmod u+w "${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones"
 echo "Movable" >"${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones"
 
 
index 5d5842c265de724ce142958fc55a85b713c14909..b273293498f5cdb8a82fc795b26990f3087f0c12 100755 (executable)
@@ -20,8 +20,6 @@ TS_DESC="x86_64_16g"
 . "$TS_TOPDIR/functions.sh"
 ts_init "$*"
 
-ts_skip_nonroot
-
 ts_check_test_command "$TS_CMD_CHMEM"
 ts_check_test_command "$TS_CMD_LSMEM"
 ts_check_prog "bzip2"
@@ -34,7 +32,7 @@ DUMP_FILENAME="$TS_SELF/sysfs-dumps/$DUMP_NAME.tar.bz2"
 DUMP_DIR="$TS_OUTDIR/sysfs-dumps"
 
 mkdir -p "$DUMP_DIR"
-tar -C "$DUMP_DIR" -jxf "$DUMP_FILENAME"
+tar --no-same-owner -C "$DUMP_DIR" -jxf "$DUMP_FILENAME"
 
 do_chmem() {
         "$TS_CMD_CHMEM" --sysroot "${DUMP_DIR}/${DUMP_NAME}" "${@}" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
@@ -76,6 +74,7 @@ mem_block="memory${index}"
 
 # We need to enable the "Movable" zone on this block first
 # otherwise chmem will complain about a zone mismatch
+chmod u+w "${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones"
 echo "Movable" >"${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones"
 
 
index 64d2e0550ee6ca0c132da52eb41d463c4ab89d20..aba9dd2fbce20860bf751eb6ffb04a59110d887f 100755 (executable)
@@ -32,7 +32,7 @@ SRCDIR="$TS_OUTDIR/testdir1"
 create_srcdir()
 {
        rm -rf "$SRCDIR"
-       tar -C "$TS_OUTDIR" -xJf "$TS_SELF/testdir1.tar.xz"
+       tar --no-same-owner -C "$TS_OUTDIR" -xJf "$TS_SELF/testdir1.tar.xz"
 }
 
 show_srcdir()
index 2c83ffc7b5c7beeb2f3fdc520e37e5e87aef7e96..b429e64bb374d7067449aea01be1c910c4f9795e 100755 (executable)
@@ -31,7 +31,7 @@ for dump in $(find "$TS_SELF"/dumps/ -maxdepth 1 -name "*.tar.xz" | sort); do
        dumpdir="$TS_OUTDIR/dumps"
 
        mkdir -p $dumpdir
-       tar -C $dumpdir --xz -xf $dump
+       tar --no-same-owner -C $dumpdir --xz -xf $dump
 
        #
        # Read *.cols from the tarball, but the expected output is not used
index 7c073835b305b34ec0d28dd29063b2b961e9f559..1c25405a6f8e4bbe15c6bc92d879eaffc5a50b8c 100755 (executable)
@@ -33,7 +33,7 @@ for dump in $(find "$TS_SELF"/dumps/ -maxdepth 1 -name "*.tar.gz" | sort); do
        ts_init_subtest $name
        mkdir -p $dumpdir
 
-       tar -C $dumpdir -zxf $dump
+       tar --no-same-owner -C $dumpdir -zxf $dump
 
        # Architecture information is not applicable with -s.
        "${TS_CMD_LSCPU}" --sysroot "${dumpdir}/${name}" | \
index c3011dcb378b62be0c61bf1b564e24d63db92f2f..abcd42e287371d5cb7f2f9e75c90f9aea9720eb7 100755 (executable)
@@ -43,7 +43,7 @@ for dump in $(find "$TS_SELF"/dumps/ -maxdepth 1 -name "*.tar.bz2" | sort); do
         ts_init_subtest $name
         mkdir -p $dumpdir
 
-        tar -C $dumpdir -jxf $dump
+        tar --no-same-owner -C $dumpdir -jxf $dump
 
         do_lsmem --split=STATE,REMOVABLE
         do_lsmem --output RANGE,SIZE --split none