Skip to content

Commit

Permalink
test: skip the symlink part of test_touch_file() in containers
Browse files Browse the repository at this point in the history
Our (RHEL 8) touch_file() is not clever enough and does chmod() on a
symlink, which fails with EOPNOTSUPP on newer kernels. This is not an
issue on the RHEL 8 kernel, where doing chmod() on a symlink works
(albeit only on tmpfs) but in GH Actions we run in a container, and with
the underlying kernel doing chmod() on a symlink fails even on tmpfs:

RHEL 8:
~# mount -t tmpfs tmpfs /tmp
~# (cd /tmp; ln -s symlink dangling; ln -s /etc/os-release symlink)
~# (cd /var/tmp; ln -s symlink dangling; ln -s /etc/os-release symlink)
~# gcc -o main main.c -D_GNU_SOURCE
~# ./main /tmp/dangling
chmod(/proc/self/fd/3)=0 (0)
~# ./main /tmp/symlink
chmod(/proc/self/fd/3)=0 (0)
~# ./main /var/tmp/dangling
chmod(/proc/self/fd/3)=-1 (95)
~# ./main /var/tmp/symlink
chmod(/proc/self/fd/3)=-1 (95)

Newer kernel:
~# uname -r
6.7.4-200.fc39.x86_64
~# ./main /tmp/dangling
chmod(/proc/self/fd/3)=-1 (95)
~# ./main /tmp/symlink
chmod(/proc/self/fd/3)=-1 (95)
~# ./main /var/tmp/dangling
chmod(/proc/self/fd/3)=-1 (95)
~# ./main /var/tmp/symlink
chmod(/proc/self/fd/3)=-1 (95)

Backporting the necessary patches would be way too risky so late in the
RHEL 8 cycle, so let's just skip the offending test when running in GH
Actions. To do that we have to jump through a couple of hoops, since
RHEL 8 systemd can't detect docker. Oh well.

See: redhat-plumbers#434

RHEL-only
  • Loading branch information
mrc0mmand committed Mar 13, 2024
1 parent f021ca0 commit 7b2cb96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ for phase in "${PHASES[@]}"; do
# unexpected fails due to incompatibilities with older systemd
$DOCKER_EXEC ninja -C build install
docker restart $CONT_NAME
$DOCKER_EXEC ninja -C build test
docker exec --interactive=false -t $CONT_NAME meson test -C ./build/ --print-errorlogs
;;
RUN_ASAN|RUN_GCC_ASAN|RUN_CLANG_ASAN)
if [[ "$phase" = "RUN_CLANG_ASAN" ]]; then
Expand Down
22 changes: 13 additions & 9 deletions src/test/test-fs-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
#include "user-util.h"
#include "util.h"
#include "virt.h"
Expand Down Expand Up @@ -544,15 +545,18 @@ static void test_touch_file(void) {
assert_se(timespec_load(&st.st_mtim) == test_mtime);
}

a = strjoina(p, "/lnk");
assert_se(symlink("target", a) >= 0);
assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0);
assert_se(lstat(a, &st) >= 0);
assert_se(st.st_uid == test_uid);
assert_se(st.st_gid == test_gid);
assert_se(S_ISLNK(st.st_mode));
assert_se((st.st_mode & 0777) == 0640);
assert_se(timespec_load(&st.st_mtim) == test_mtime);
log_warning("%s: ci_environment()=%s", __func__, ci_environment());
if (streq_ptr(ci_environment(), "github-actions")) {
a = strjoina(p, "/lnk");
assert_se(symlink("target", a) >= 0);
assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0);
assert_se(lstat(a, &st) >= 0);
assert_se(st.st_uid == test_uid);
assert_se(st.st_gid == test_gid);
assert_se(S_ISLNK(st.st_mode));
assert_se((st.st_mode & 0777) == 0640);
assert_se(timespec_load(&st.st_mtim) == test_mtime);
}
}

static void test_unlinkat_deallocate(void) {
Expand Down

0 comments on commit 7b2cb96

Please sign in to comment.