1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

test: add tests for dir_fd_is_root_or_cwd()

Follow-up for e212f422796da9e626030289faf083407c8955df.
This commit is contained in:
Yu Watanabe 2023-04-05 15:23:19 +09:00 committed by Luca Boccassi
parent cad0fc7a13
commit 70650ae345

View 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) {