summaryrefslogtreecommitdiffstats
path: root/src/test/test-fd-util.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-02-01 13:14:29 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-15 11:51:08 +0100
commitaf423b4ba9c6074020a8ec1dbfe9de10020b1f19 (patch)
tree0e6ed1d4aa836c7f67e1ee673409baa890e8614e /src/test/test-fd-util.c
parentmountpoint-util: Add path_get_mnt_id_at() (diff)
downloadsystemd-af423b4ba9c6074020a8ec1dbfe9de10020b1f19.tar.xz
systemd-af423b4ba9c6074020a8ec1dbfe9de10020b1f19.zip
fd-util: Add dir_fd_is_root()
Diffstat (limited to 'src/test/test-fd-util.c')
-rw-r--r--src/test/test-fd-util.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c
index 1ca9ef8bbd..c5f32aa679 100644
--- a/src/test/test-fd-util.c
+++ b/src/test/test-fd-util.c
@@ -569,4 +569,16 @@ TEST(take_fd) {
assert_se(array[1] == -EBADF);
}
+TEST(dir_fd_is_root) {
+ _cleanup_close_ int fd = -EBADF;
+
+ assert_se((fd = open("/", O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW)) >= 0);
+ assert_se(dir_fd_is_root(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);
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);