mirror of
https://github.com/systemd/systemd.git
synced 2026-08-07 08:30:57 +00:00
fd-util: rename fds_are_same_mount() fds_inode_and_mount_same()
The old name suggested this would only check if the two inodes are on the same mount, but it actually checks if they are the same inodes too. Let's rename it to make this clearer, in particular as we have both statx_inode_same() and statx_mount_same() already, and they are even used here, and hence very confusing. This also drops two checks from the test case, which are simply wrong. Given they apparently weren't load bearing (since no CI tripped up), let's just drop them.
This commit is contained in:
@@ -1069,10 +1069,10 @@ int path_is_root_at(int dir_fd, const char *path) {
|
||||
* $ 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;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ static inline int dir_fd_is_root_or_cwd(int dir_fd) {
|
||||
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);
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ int switch_root(const char *new_root,
|
||||
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) {
|
||||
|
||||
@@ -738,7 +738,7 @@ TEST(path_is_root_at) {
|
||||
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);
|
||||
@@ -749,11 +749,8 @@ TEST(fds_are_same_mount) {
|
||||
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) {
|
||||
|
||||
@@ -871,10 +871,10 @@ TEST(xat_fdroot) {
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user