]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add tests for dir_fd_is_root_or_cwd()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 5 Apr 2023 06:23:19 +0000 (15:23 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 5 Apr 2023 18:38:08 +0000 (19:38 +0100)
Follow-up for e212f422796da9e626030289faf083407c8955df.

src/test/test-fd-util.c

index adcd851d7f54b3a1889651bf74228320eb2110c2..c902f83784b321db4e1e63c352942a234556f2fe 100644 (file)
@@ -597,13 +597,17 @@ TEST(dir_fd_is_root) {
         _cleanup_close_ int fd = -EBADF;
         int r;
 
+        assert_se(dir_fd_is_root_or_cwd(AT_FDCWD) > 0);
+
         assert_se((fd = open("/", O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW)) >= 0);
         assert_se(dir_fd_is_root(fd) > 0);
+        assert_se(dir_fd_is_root_or_cwd(fd) > 0);
 
         fd = safe_close(fd);
 
         assert_se((fd = open("/usr", O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW)) >= 0);
         assert_se(dir_fd_is_root(fd) == 0);
+        assert_se(dir_fd_is_root_or_cwd(fd) == 0);
 
         r = detach_mount_namespace();
         if (r < 0)
@@ -622,16 +626,19 @@ TEST(dir_fd_is_root) {
 
         assert_se((fd = open(tmp, O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW)) >= 0);
         assert_se(dir_fd_is_root(fd) == 0);
+        assert_se(dir_fd_is_root_or_cwd(fd) == 0);
 
         fd = safe_close(fd);
 
         assert_se((fd = open(x, O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW)) >= 0);
         assert_se(dir_fd_is_root(fd) == 0);
+        assert_se(dir_fd_is_root_or_cwd(fd) == 0);
 
         fd = safe_close(fd);
 
         assert_se((fd = open(y, O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW)) >= 0);
         assert_se(dir_fd_is_root(fd) == 0);
+        assert_se(dir_fd_is_root_or_cwd(fd) == 0);
 }
 
 TEST(fd_get_path) {