]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: port various places over to new stat_inode_same() helper
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Feb 2022 16:21:41 +0000 (17:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 Feb 2022 16:27:14 +0000 (17:27 +0100)
src/basic/fd-util.c
src/basic/fs-util.c
src/basic/mountpoint-util.c
src/basic/stat-util.c
src/coredump/coredump-vacuum.c
src/libsystemd/sd-daemon/sd-daemon.c
src/libsystemd/sd-device/device-monitor.c
src/libsystemd/sd-journal/sd-journal.c
src/resolve/resolved-resolv-conf.c
src/shared/mount-util.c

index 3866e876754ccade3d166b780f01e240691ec58b..a0836aabd1541bc22640f8cf6a0e575e55448d69 100644 (file)
@@ -446,7 +446,7 @@ int same_fd(int a, int b) {
         if (fstat(b, &stb) < 0)
                 return -errno;
 
-        if ((sta.st_mode & S_IFMT) != (stb.st_mode & S_IFMT))
+        if (!stat_inode_same(&sta, &stb))
                 return false;
 
         /* We consider all device fds different, since two device fds
@@ -456,13 +456,8 @@ int same_fd(int a, int b) {
         if (S_ISCHR(sta.st_mode) || S_ISBLK(sta.st_mode))
                 return false;
 
-        if (sta.st_dev != stb.st_dev || sta.st_ino != stb.st_ino)
-                return false;
-
-        /* The fds refer to the same inode on disk, let's also check
-         * if they have the same fd flags. This is useful to
-         * distinguish the read and write side of a pipe created with
-         * pipe(). */
+        /* The fds refer to the same inode on disk, let's also check if they have the same fd flags. This is
+         * useful to distinguish the read and write side of a pipe created with pipe(). */
         fa = fcntl(a, F_GETFL);
         if (fa < 0)
                 return -errno;
index 552986f546664a63f76da1b37105b646ba1921ec..11039fd75d587ebc60c3ab2891319e61fa3ed3d1 100644 (file)
@@ -856,8 +856,7 @@ int conservative_renameat(
         if (fstat(new_fd, &new_stat) < 0)
                 goto do_rename;
 
-        if (new_stat.st_ino == old_stat.st_ino &&
-            new_stat.st_dev == old_stat.st_dev)
+        if (stat_inode_same(&new_stat, &old_stat))
                 goto is_same;
 
         if (old_stat.st_mode != new_stat.st_mode ||
index 82a33a68295e326ccfb0269f0157186b11b038ee..2e451085beccf48e83f48bdad6e56ea751fca980 100644 (file)
@@ -298,10 +298,8 @@ fallback_fstat:
         if (fstatat(fd, "", &b, AT_EMPTY_PATH) < 0)
                 return -errno;
 
-        /* A directory with same device and inode as its parent? Must
-         * be the root directory */
-        if (a.st_dev == b.st_dev &&
-            a.st_ino == b.st_ino)
+        /* A directory with same device and inode as its parent? Must be the root directory */
+        if (stat_inode_same(&a, &b))
                 return 1;
 
         return check_st_dev && (a.st_dev != b.st_dev);
index 298f46440fab540fc42a86787459fc366efe42a6..96364b81ac7e8aff1200920b1b278250903e5980 100644 (file)
@@ -185,8 +185,7 @@ int files_same(const char *filea, const char *fileb, int flags) {
         if (fstatat(AT_FDCWD, fileb, &b, flags) < 0)
                 return -errno;
 
-        return a.st_dev == b.st_dev &&
-               a.st_ino == b.st_ino;
+        return stat_inode_same(&a, &b);
 }
 
 bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) {
index dcf9cc03cd26c7661f10c3185b717363ed60f2c8..c6e201ecf20badcc432ab6489551bc2040ca5383 100644 (file)
@@ -13,6 +13,7 @@
 #include "hashmap.h"
 #include "macro.h"
 #include "memory-util.h"
+#include "stat-util.h"
 #include "string-util.h"
 #include "time-util.h"
 #include "user-util.h"
@@ -167,9 +168,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
                         if (!S_ISREG(st.st_mode))
                                 continue;
 
-                        if (exclude_fd >= 0 &&
-                            exclude_st.st_dev == st.st_dev &&
-                            exclude_st.st_ino == st.st_ino)
+                        if (exclude_fd >= 0 && stat_inode_same(&exclude_st, &st))
                                 continue;
 
                         r = hashmap_ensure_allocated(&h, NULL);
index b373c173c158498a2dcd2e9e04939219d4da2946..b5f62ec5e871d17b4e75b092903836c125faba6d 100644 (file)
@@ -23,6 +23,7 @@
 #include "path-util.h"
 #include "process-util.h"
 #include "socket-util.h"
+#include "stat-util.h"
 #include "strv.h"
 #include "time-util.h"
 #include "util.h"
@@ -150,9 +151,7 @@ _public_ int sd_is_fifo(int fd, const char *path) {
                         return -errno;
                 }
 
-                return
-                        st_path.st_dev == st_fd.st_dev &&
-                        st_path.st_ino == st_fd.st_ino;
+                return stat_inode_same(&st_path, &st_fd);
         }
 
         return 1;
@@ -181,9 +180,7 @@ _public_ int sd_is_special(int fd, const char *path) {
                 }
 
                 if (S_ISREG(st_fd.st_mode) && S_ISREG(st_path.st_mode))
-                        return
-                                st_path.st_dev == st_fd.st_dev &&
-                                st_path.st_ino == st_fd.st_ino;
+                        return stat_inode_same(&st_path, &st_fd);
                 else if (S_ISCHR(st_fd.st_mode) && S_ISCHR(st_path.st_mode))
                         return st_path.st_rdev == st_fd.st_rdev;
                 else
@@ -429,8 +426,7 @@ _public_ int sd_is_mq(int fd, const char *path) {
                 if (stat(fpath, &b) < 0)
                         return -errno;
 
-                if (a.st_dev != b.st_dev ||
-                    a.st_ino != b.st_ino)
+                if (!stat_inode_same(&a, &b))
                         return 0;
         }
 
index 524d10b9d801ae6ca77c3b72389cedf4ac157c71..80cb0ce622ca25d44222c4c32cc417e4e5cd47c6 100644 (file)
@@ -24,6 +24,7 @@
 #include "mountpoint-util.h"
 #include "set.h"
 #include "socket-util.h"
+#include "stat-util.h"
 #include "string-util.h"
 #include "strv.h"
 
@@ -195,7 +196,7 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
                                 else
                                         log_debug_errno(errno, "sd-device-monitor: Failed to stat PID1's netns, ignoring: %m");
 
-                        } else if (a.st_dev != b.st_dev || a.st_ino != b.st_ino)
+                        } else if (!stat_inode_same(&a, &b))
                                 log_debug("sd-device-monitor: Netlink socket we listen on is not from host netns, we won't see device events.");
                 }
         }
index 644b9957b0e01d638014457f7c8d8b894a94054e..399e33fa2b8dc9f1d305232af82755b487b59f93 100644 (file)
@@ -1317,8 +1317,7 @@ static int add_any_file(
 
         f = ordered_hashmap_get(j->files, path);
         if (f) {
-                if (f->last_stat.st_dev == st.st_dev &&
-                    f->last_stat.st_ino == st.st_ino) {
+                if (stat_inode_same(&f->last_stat, &st)) {
 
                         /* We already track this file, under the same path and with the same device/inode numbers, it's
                          * hence really the same. Mark this file as seen in this generation. This is used to GC old
index e9785ab964b45bc5d750446b729e82537c42102f..0a5c775d3172203ec7b19898be4f445f2b424b17 100644 (file)
@@ -41,8 +41,7 @@ int manager_check_resolv_conf(const Manager *m) {
 
         /* Is it symlinked to our own uplink file? */
         if (stat(PRIVATE_STATIC_RESOLV_CONF, &own) >= 0 &&
-            st.st_dev == own.st_dev &&
-            st.st_ino == own.st_ino)
+            stat_inode_same(&st, &own))
                 return log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
                                          "DNSStubListener= is disabled, but /etc/resolv.conf is a symlink to "
                                          PRIVATE_STATIC_RESOLV_CONF " which expects DNSStubListener= to be enabled.");
@@ -64,8 +63,7 @@ static bool file_is_our_own(const struct stat *st) {
 
                 /* Is it symlinked to our own uplink file? */
                 if (stat(path, &own) >= 0 &&
-                    st->st_dev == own.st_dev &&
-                    st->st_ino == own.st_ino)
+                    stat_inode_same(st, &own))
                         return true;
         }
 
@@ -418,8 +416,7 @@ int resolv_conf_mode(void) {
                         continue;
                 }
 
-                if (system_st.st_dev == our_st.st_dev &&
-                    system_st.st_ino == our_st.st_ino)
+                if (stat_inode_same(&system_st, &our_st))
                         return m;
         }
 
index 6e938fc19db47b7aaa88e1d4e9a17fb3c12f71a0..7f88a982bd7920dac8955602769f1a5b739e4bc5 100644 (file)
@@ -816,7 +816,7 @@ static int mount_in_namespace(
                 return log_debug_errno(errno, "Failed to fstat mount namespace FD of systemd: %m");
 
         /* We can't add new mounts at runtime if the process wasn't started in a namespace */
-        if (st.st_ino == self_mntns_st.st_ino && st.st_dev == self_mntns_st.st_dev)
+        if (stat_inode_same(&st, &self_mntns_st))
                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace");
 
         /* One day, when bind mounting /proc/self/fd/n works across namespace boundaries we should rework