* $ mount --bind / /tmp/x
*/
- return fds_are_same_mount(dir_fd, XAT_FDROOT);
+ return fds_inode_and_mount_same(dir_fd, XAT_FDROOT);
}
-int fds_are_same_mount(int fd1, int fd2) {
+int fds_inode_and_mount_same(int fd1, int fd2) {
struct statx sx1, sx2;
int r;
return IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT) ? true : path_is_root_at(dir_fd, NULL);
}
-int fds_are_same_mount(int fd1, int fd2);
+int fds_inode_and_mount_same(int fd1, int fd2);
int resolve_xat_fdroot(int *fd, const char **path, char **ret_buffer);
if (new_root_fd < 0)
return log_error_errno(errno, "Failed to open target directory '%s': %m", new_root);
- r = fds_are_same_mount(old_root_fd, new_root_fd); /* checks if referenced inodes and mounts match */
+ r = fds_inode_and_mount_same(old_root_fd, new_root_fd); /* checks if referenced inodes and mounts match */
if (r < 0)
return log_error_errno(r, "Failed to check if old and new root directory/mount are the same: %m");
if (r > 0) {
test_path_is_root_at_one(true);
}
-TEST(fds_are_same_mount) {
+TEST(fds_inode_and_mount_same) {
_cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF, fd3 = -EBADF, fd4 = -EBADF;
fd1 = open("/sys", O_CLOEXEC|O_PATH|O_DIRECTORY|O_NOFOLLOW);
if (fd1 < 0 || fd2 < 0 || fd3 < 0 || fd4 < 0)
return (void) log_tests_skipped_errno(errno, "Failed to open /sys or /proc or /");
- if (fds_are_same_mount(fd1, fd4) > 0 && fds_are_same_mount(fd2, fd4) > 0)
- return (void) log_tests_skipped("Cannot test fds_are_same_mount() as /sys and /proc are not mounted");
-
- assert_se(fds_are_same_mount(fd1, fd2) == 0);
- assert_se(fds_are_same_mount(fd2, fd3) > 0);
+ assert_se(fds_inode_and_mount_same(fd1, fd2) == 0);
+ assert_se(fds_inode_and_mount_same(fd2, fd3) > 0);
}
TEST(fd_get_path) {
ASSERT_OK_POSITIVE(path_is_root_at(fd, "."));
ASSERT_OK_POSITIVE(path_is_root_at(fd, "/"));
- ASSERT_OK_POSITIVE(fds_are_same_mount(fd, fd));
- ASSERT_OK_POSITIVE(fds_are_same_mount(XAT_FDROOT, XAT_FDROOT));
- ASSERT_OK_POSITIVE(fds_are_same_mount(fd, XAT_FDROOT));
- ASSERT_OK_POSITIVE(fds_are_same_mount(XAT_FDROOT, fd));
+ ASSERT_OK_POSITIVE(fds_inode_and_mount_same(fd, fd));
+ ASSERT_OK_POSITIVE(fds_inode_and_mount_same(XAT_FDROOT, XAT_FDROOT));
+ ASSERT_OK_POSITIVE(fds_inode_and_mount_same(fd, XAT_FDROOT));
+ ASSERT_OK_POSITIVE(fds_inode_and_mount_same(XAT_FDROOT, fd));
ASSERT_OK_POSITIVE(dir_fd_is_root(XAT_FDROOT));
ASSERT_OK_POSITIVE(dir_fd_is_root(fd));