]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-fd-util: compare FDs to /bin/sh instead of /dev/null 35556/head
authorLuca Boccassi <luca.boccassi@gmail.com>
Wed, 11 Dec 2024 13:40:10 +0000 (13:40 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 11 Dec 2024 13:42:11 +0000 (13:42 +0000)
/dev/null is a character device, so same_fd() in the fallback path
that compares fstat will fail, as that bails out if the fd refers
to a char device. This happens on kernels without F_DUPFD_QUERY and
without kcmp.

/* test_same_fd */
Assertion 'same_fd(d, e) > 0' failed at src/test/test-fd-util.c:111, function test_same_fd(). Aborting.

Fixes #35552

src/test/test-fd-util.c

index 5817d92725254d3d2b5f6bebfbdf79d8d435d5a1..a359efa0525c67c47ba48aa5983fe33d8a9eee23 100644 (file)
@@ -76,9 +76,9 @@ TEST(same_fd) {
 
         assert_se(pipe2(p, O_CLOEXEC) >= 0);
         assert_se((a = fcntl(p[0], F_DUPFD, 3)) >= 0);
-        assert_se((b = open("/dev/null", O_RDONLY|O_CLOEXEC)) >= 0);
+        assert_se((b = open("/bin/sh", O_RDONLY|O_CLOEXEC)) >= 0);
         assert_se((c = fcntl(a, F_DUPFD, 3)) >= 0);
-        assert_se((d = open("/dev/null", O_RDONLY|O_CLOEXEC|O_PATH)) >= 0); /* O_PATH changes error returns in F_DUPFD_QUERY, let's test explicitly */
+        assert_se((d = open("/bin/sh", O_RDONLY|O_CLOEXEC|O_PATH)) >= 0); /* O_PATH changes error returns in F_DUPFD_QUERY, let's test explicitly */
         assert_se((e = fcntl(d, F_DUPFD, 3)) >= 0);
 
         assert_se(same_fd(p[0], p[0]) > 0);