From: Yu Watanabe Date: Wed, 5 Apr 2023 06:23:19 +0000 (+0900) Subject: test: add tests for dir_fd_is_root_or_cwd() X-Git-Tag: v254-rc1~801 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70650ae345801f4e1fd94c2cacd1b95ff174a60d;p=thirdparty%2Fsystemd.git test: add tests for dir_fd_is_root_or_cwd() Follow-up for e212f422796da9e626030289faf083407c8955df. --- diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c index adcd851d7f5..c902f83784b 100644 --- a/src/test/test-fd-util.c +++ b/src/test/test-fd-util.c @@ -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) {