]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: rename files_same() → inode_same()
authorLennart Poettering <lennart@poettering.net>
Fri, 19 May 2023 12:47:37 +0000 (14:47 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 May 2023 15:42:41 +0000 (17:42 +0200)
Let's be more accurate about what this function does: it checks whether
the underlying reported inode is the same. Internally, this already uses
a better named stat_inode_same() call, hence let's similarly name the
wrapping function following the same logic.

Similar for files_same_at() and path_equal_or_same_files().

No code changes, just some renaming.

16 files changed:
src/basic/namespace-util.c
src/basic/path-util.c
src/basic/path-util.h
src/basic/process-util.c
src/basic/socket-util.c
src/basic/stat-util.c
src/basic/stat-util.h
src/basic/virt.c
src/core/socket.c
src/mount/mount-tool.c
src/shared/install.c
src/shared/rm-rf.c
src/shared/switch-root.c
src/test/test-path-util.c
src/test/test-specifier.c
src/test/test-stat-util.c

index f511a91720a0bc95d3204c29c22f9f51ecb21acb..27c760c3ef0e108cc3dd76674701624c3331c76e 100644 (file)
@@ -109,7 +109,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
                 /* Can't setns to your own userns, since then you could escalate from non-root to root in
                  * your own namespace, so check if namespaces are equal before attempting to enter. */
 
-                r = files_same(FORMAT_PROC_FD_PATH(userns_fd), "/proc/self/ns/user", 0);
+                r = inode_same(FORMAT_PROC_FD_PATH(userns_fd), "/proc/self/ns/user", 0);
                 if (r < 0)
                         return r;
                 if (r)
index a68106556568e5ed9692b2e30f1488a8105e9810..e1cc26f618bbe8f7abc19953e9f83d5106065f79 100644 (file)
@@ -485,8 +485,8 @@ int path_compare(const char *a, const char *b) {
         }
 }
 
-bool path_equal_or_files_same(const char *a, const char *b, int flags) {
-        return path_equal(a, b) || files_same(a, b, flags) > 0;
+bool path_equal_or_inode_same(const char *a, const char *b, int flags) {
+        return path_equal(a, b) || inode_same(a, b, flags) > 0;
 }
 
 int path_compare_filename(const char *a, const char *b) {
index 7843599816e69972bc283daf7e074df654adbe0d..66879d1932abfcd81325efaaf755b72dd7c0caf3 100644 (file)
@@ -77,7 +77,7 @@ static inline bool path_equal_filename(const char *a, const char *b) {
         return path_compare_filename(a, b) == 0;
 }
 
-bool path_equal_or_files_same(const char *a, const char *b, int flags);
+bool path_equal_or_inode_same(const char *a, const char *b, int flags);
 
 char* path_extend_internal(char **x, ...);
 #define path_extend(x, ...) path_extend_internal(x, __VA_ARGS__, POINTER_MAX)
index 7de7d80cd4aa33261e04653356b3df9baa1b04fc..0f642fdf1bb3f469567f2607009488e6966723e2 100644 (file)
@@ -946,7 +946,7 @@ int pid_from_same_root_fs(pid_t pid) {
 
         root = procfs_file_alloca(pid, "root");
 
-        return files_same(root, "/proc/1/root", 0);
+        return inode_same(root, "/proc/1/root", 0);
 }
 
 bool is_main_thread(void) {
index 5b76948c0648712e2dba170ff6c02dc35093088f..9040ff7c53471dcb38d0dcc68ea09315bd86d620 100644 (file)
@@ -223,7 +223,7 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
                         return false;
 
                 if (a->sockaddr.un.sun_path[0]) {
-                        if (!path_equal_or_files_same(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, 0))
+                        if (!path_equal_or_inode_same(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, 0))
                                 return false;
                 } else {
                         if (a->size != b->size)
index 20152fbe2b48fbc442c13f2314777dc5d625b608..843cc025dc8468831a71f400252d8ded3b770356 100644 (file)
@@ -183,7 +183,7 @@ int path_is_read_only_fs(const char *path) {
         return fd_is_read_only_fs(fd);
 }
 
-int files_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags) {
+int inode_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags) {
         struct stat a, b;
 
         assert(fda >= 0 || fda == AT_FDCWD);
index 25f915f558b524681b381a08abb7c0a3791069a0..3ae8b3eeb1bffaa9ba88b0e9232c64d09746766c 100644 (file)
@@ -37,10 +37,10 @@ static inline int null_or_empty_path(const char *fn) {
 
 int path_is_read_only_fs(const char *path);
 
-int files_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags);
+int inode_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags);
 
-static inline int files_same(const char *filea, const char *fileb, int flags) {
-        return files_same_at(AT_FDCWD, filea, AT_FDCWD, fileb, flags);
+static inline int inode_same(const char *filea, const char *fileb, int flags) {
+        return inode_same_at(AT_FDCWD, filea, AT_FDCWD, fileb, flags);
 }
 
 /* The .f_type field of struct statfs is really weird defined on
index aadc923bb54f93f2d0580d01fef124cbeee19ff4..79fa43e0d82483a49e120eed5196b5bc5ff4fb1b 100644 (file)
@@ -891,7 +891,7 @@ int running_in_chroot(void) {
         if (getpid_cached() == 1)
                 return false;  /* We're PID 1, we can't be in a chroot. */
 
-        r = files_same("/proc/1/root", "/", 0);
+        r = inode_same("/proc/1/root", "/", 0);
         if (r == -ENOENT) {
                 r = proc_mounted();
                 if (r == 0) {
index 0fd1ad144b086e6928b80a2473f98dce6d665b0a..2ed6611c9f1e76731d510baa69e1f0b33f09fcff 100644 (file)
@@ -2671,7 +2671,7 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
                 LIST_FOREACH(port, p, s->ports)
                         if (p->fd < 0 &&
                             p->type == SOCKET_FIFO &&
-                            path_equal_or_files_same(p->path, value, 0)) {
+                            path_equal_or_inode_same(p->path, value, 0)) {
                                 p->fd = fdset_remove(fds, fd);
                                 found = true;
                                 break;
@@ -2699,7 +2699,7 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
                 LIST_FOREACH(port, p, s->ports)
                         if (p->fd < 0 &&
                             p->type == SOCKET_SPECIAL &&
-                            path_equal_or_files_same(p->path, value, 0)) {
+                            path_equal_or_inode_same(p->path, value, 0)) {
                                 p->fd = fdset_remove(fds, fd);
                                 found = true;
                                 break;
@@ -2821,7 +2821,7 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
                 LIST_FOREACH(port, p, s->ports)
                         if (p->fd < 0 &&
                             p->type == SOCKET_USB_FUNCTION &&
-                            path_equal_or_files_same(p->path, value, 0)) {
+                            path_equal_or_inode_same(p->path, value, 0)) {
                                 p->fd = fdset_remove(fds, fd);
                                 found = true;
                                 break;
index 5f5d84bb9718c1545d19f194ddc760e710e85415..dd07e16c725645ba4bb9db8bbffd0a83f2ef4eb0 100644 (file)
@@ -814,7 +814,7 @@ static int find_loop_device(const char *backing_file, sd_device **ret) {
                         continue;
                 }
 
-                if (files_same(s, backing_file, 0) <= 0)
+                if (inode_same(s, backing_file, 0) <= 0)
                         continue;
 
                 *ret = sd_device_ref(dev);
index 7903de17b1a5e71b0ed5456cff2b6e9664ec8e63..a34e7bfe5ba10bffa753db629f864c00ecb9c509 100644 (file)
@@ -493,7 +493,7 @@ static int chroot_unit_symlinks_equivalent(
         if (!a || !b)
                 return log_oom();
 
-        r = path_equal_or_files_same(a, b, 0);
+        r = path_equal_or_inode_same(a, b, 0);
         if (r != 0)
                 return r;
 
index e99c321418df3f613d79dd2210e3cb1ab19675ed..8e459f9d693d83d2c424700487df7ebfaf22ea46 100644 (file)
@@ -438,7 +438,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
 
         /* We refuse to clean the root file system with this call. This is extra paranoia to never cause a
          * really seriously broken system. */
-        if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW))
+        if (path_equal_or_inode_same(path, "/", AT_SYMLINK_NOFOLLOW))
                 return log_error_errno(SYNTHETIC_ERRNO(EPERM),
                                        "Attempted to remove entire root file system (\"%s\"), and we can't allow that.",
                                        path);
index 118eaac78efa455f4079dae6a4347357f4fa1a97..c7b562143dd9817a4baa13e7d5b2df90023754dc 100644 (file)
@@ -45,7 +45,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 = files_same_at(old_root_fd, "", new_root_fd, "", AT_EMPTY_PATH);
+        r = inode_same_at(old_root_fd, "", new_root_fd, "", AT_EMPTY_PATH);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine if old and new root directory are the same: %m");
         if (r > 0) {
index e40ffea4d53e72726e70390c11421229c6981c3d..6b685a816f0bf06d17f152173084c1126df52d0b 100644 (file)
@@ -207,33 +207,33 @@ TEST(path_equal_root) {
 
         /* Make sure that files_same works as expected. */
 
-        assert_se(files_same("/", "/", 0) > 0);
-        assert_se(files_same("/", "/", AT_SYMLINK_NOFOLLOW) > 0);
-        assert_se(files_same("/", "//", 0) > 0);
-        assert_se(files_same("/", "//", AT_SYMLINK_NOFOLLOW) > 0);
+        assert_se(inode_same("/", "/", 0) > 0);
+        assert_se(inode_same("/", "/", AT_SYMLINK_NOFOLLOW) > 0);
+        assert_se(inode_same("/", "//", 0) > 0);
+        assert_se(inode_same("/", "//", AT_SYMLINK_NOFOLLOW) > 0);
 
-        assert_se(files_same("/", "/./", 0) > 0);
-        assert_se(files_same("/", "/./", AT_SYMLINK_NOFOLLOW) > 0);
-        assert_se(files_same("/", "/../", 0) > 0);
-        assert_se(files_same("/", "/../", AT_SYMLINK_NOFOLLOW) > 0);
+        assert_se(inode_same("/", "/./", 0) > 0);
+        assert_se(inode_same("/", "/./", AT_SYMLINK_NOFOLLOW) > 0);
+        assert_se(inode_same("/", "/../", 0) > 0);
+        assert_se(inode_same("/", "/../", AT_SYMLINK_NOFOLLOW) > 0);
 
-        assert_se(files_same("/", "/.../", 0) == -ENOENT);
-        assert_se(files_same("/", "/.../", AT_SYMLINK_NOFOLLOW) == -ENOENT);
+        assert_se(inode_same("/", "/.../", 0) == -ENOENT);
+        assert_se(inode_same("/", "/.../", AT_SYMLINK_NOFOLLOW) == -ENOENT);
 
         /* The same for path_equal_or_files_same. */
 
-        assert_se(path_equal_or_files_same("/", "/", 0));
-        assert_se(path_equal_or_files_same("/", "/", AT_SYMLINK_NOFOLLOW));
-        assert_se(path_equal_or_files_same("/", "//", 0));
-        assert_se(path_equal_or_files_same("/", "//", AT_SYMLINK_NOFOLLOW));
+        assert_se(path_equal_or_inode_same("/", "/", 0));
+        assert_se(path_equal_or_inode_same("/", "/", AT_SYMLINK_NOFOLLOW));
+        assert_se(path_equal_or_inode_same("/", "//", 0));
+        assert_se(path_equal_or_inode_same("/", "//", AT_SYMLINK_NOFOLLOW));
 
-        assert_se(path_equal_or_files_same("/", "/./", 0));
-        assert_se(path_equal_or_files_same("/", "/./", AT_SYMLINK_NOFOLLOW));
-        assert_se(path_equal_or_files_same("/", "/../", 0));
-        assert_se(path_equal_or_files_same("/", "/../", AT_SYMLINK_NOFOLLOW));
+        assert_se(path_equal_or_inode_same("/", "/./", 0));
+        assert_se(path_equal_or_inode_same("/", "/./", AT_SYMLINK_NOFOLLOW));
+        assert_se(path_equal_or_inode_same("/", "/../", 0));
+        assert_se(path_equal_or_inode_same("/", "/../", AT_SYMLINK_NOFOLLOW));
 
-        assert_se(!path_equal_or_files_same("/", "/.../", 0));
-        assert_se(!path_equal_or_files_same("/", "/.../", AT_SYMLINK_NOFOLLOW));
+        assert_se(!path_equal_or_inode_same("/", "/.../", 0));
+        assert_se(!path_equal_or_inode_same("/", "/.../", AT_SYMLINK_NOFOLLOW));
 }
 
 TEST(find_executable_full) {
index 1e4659984388b8f7b221492bb214e3f8f315cec2..d6a8b79aa4ac6693f4c08b0d5ba0bf40731fa576 100644 (file)
@@ -106,7 +106,7 @@ TEST(specifier_real_path) {
         puts(strnull(w));
 
         /* /dev/initctl should normally be a symlink to /run/initctl */
-        if (files_same("/dev/initctl", "/run/initctl", 0) > 0)
+        if (inode_same("/dev/initctl", "/run/initctl", 0) > 0)
                 assert_se(streq(w, "p=/dev/initctl y=/run/initctl Y=/run w=/dev/tty W=/dev"));
 }
 
index f79b05a4d1b629075f3576fbfb0201077e148796..5aca207fa42c9202f87287a3c9c56d999d24abae 100644 (file)
@@ -42,7 +42,7 @@ TEST(null_or_empty_path_with_root) {
         assert_se(null_or_empty_path_with_root("/foobar/barbar/dev/null", "/foobar/barbar/") == 1);
 }
 
-TEST(files_same) {
+TEST(inode_same) {
         _cleanup_close_ int fd = -EBADF;
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-files_same.XXXXXX";
         _cleanup_(unlink_tempfilep) char name_alias[] = "/tmp/test-files_same.alias";
@@ -51,10 +51,10 @@ TEST(files_same) {
         assert_se(fd >= 0);
         assert_se(symlink(name, name_alias) >= 0);
 
-        assert_se(files_same(name, name, 0));
-        assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW));
-        assert_se(files_same(name, name_alias, 0));
-        assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
+        assert_se(inode_same(name, name, 0));
+        assert_se(inode_same(name, name, AT_SYMLINK_NOFOLLOW));
+        assert_se(inode_same(name, name_alias, 0));
+        assert_se(!inode_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
 }
 
 TEST(is_symlink) {