diff options
Diffstat (limited to 'src/test/test-mountpoint-util.c')
-rw-r--r-- | src/test/test-mountpoint-util.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index 287488b7c1..47fde5cb2c 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -256,6 +256,37 @@ static void test_path_is_mount_point(void) { assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0); } +static void test_fd_is_mount_point(void) { + _cleanup_close_ int fd = -1; + + log_info("/* %s */", __func__); + + fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY); + assert_se(fd >= 0); + + /* Not allowed, since "/" is a path, not a plain filename */ + assert_se(fd_is_mount_point(fd, "/", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, ".", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "./", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "..", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "../", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "/proc", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "/proc/", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "proc/sys", 0) == -EINVAL); + assert_se(fd_is_mount_point(fd, "proc/sys/", 0) == -EINVAL); + + /* This one definitely is a mount point */ + assert_se(fd_is_mount_point(fd, "proc", 0) > 0); + assert_se(fd_is_mount_point(fd, "proc/", 0) > 0); + + /* /root's entire raison d'etre is to be on the root file system (i.e. not in /home/ which might be + * split off), so that the user can always log in, so it cannot be a mount point unless the system is + * borked. Let's allow for it to be missing though. */ + assert_se(IN_SET(fd_is_mount_point(fd, "root", 0), -ENOENT, 0)); + assert_se(IN_SET(fd_is_mount_point(fd, "root/", 0), -ENOENT, 0)); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_DEBUG); @@ -279,6 +310,7 @@ int main(int argc, char *argv[]) { test_mnt_id(); test_path_is_mount_point(); + test_fd_is_mount_point(); return 0; } |