]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: rename fds_are_same_mount() fds_inode_and_mount_same()
authorLennart Poettering <lennart@amutable.com>
Wed, 25 Feb 2026 12:06:32 +0000 (13:06 +0100)
committerLennart Poettering <lennart@amutable.com>
Tue, 3 Mar 2026 07:48:01 +0000 (08:48 +0100)
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.

src/basic/fd-util.c
src/basic/fd-util.h
src/shared/switch-root.c
src/test/test-fd-util.c
src/test/test-fs-util.c

index d043927a2c9ec9ae079b273fe34a38911c621e8c..4d720e014eef93f818f44f4401d26ced6ee48389 100644 (file)
@@ -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;
 
index ee1dc870df85940b8dd464e54ba988524c9dd0d9..60caa424b4e1da68fed796f906211ab7eabcd5f0 100644 (file)
@@ -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);
 
index 6017200d79c3ea8105ed8f524add3a572e3d1b3f..08710a896640041b5218404844b38bd03357b55c 100644 (file)
@@ -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) {
index d43c8735164d50db21628dcc3d558a871fa09649..e99d7d04726b42c9857071b481b8aa60dab5c38f 100644 (file)
@@ -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) {
index a56f8f92ada9af53f44fb176967d98c9e010e2a4..7cb720938ccefac820d2b7c0cba28d3cc7305acd 100644 (file)
@@ -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));