summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-14 17:21:41 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-14 17:27:14 +0100
commita9dac7a6dd31225dbe9633061dcade12c0c90a32 (patch)
tree9fdf4d4480ecc18aa7306f8eddce2d9f5a8649d3 /src
parent38db6211b5aa6e2fb65883ae3353914e82f5bef1 (diff)
downloadsystemd-a9dac7a6dd31225dbe9633061dcade12c0c90a32.tar.gz
tree-wide: port various places over to new stat_inode_same() helper
Diffstat (limited to 'src')
-rw-r--r--src/basic/fd-util.c11
-rw-r--r--src/basic/fs-util.c3
-rw-r--r--src/basic/mountpoint-util.c6
-rw-r--r--src/basic/stat-util.c3
-rw-r--r--src/coredump/coredump-vacuum.c5
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c12
-rw-r--r--src/libsystemd/sd-device/device-monitor.c3
-rw-r--r--src/libsystemd/sd-journal/sd-journal.c3
-rw-r--r--src/resolve/resolved-resolv-conf.c9
-rw-r--r--src/shared/mount-util.c2
10 files changed, 20 insertions, 37 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index 3866e87675..a0836aabd1 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -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;
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 552986f546..11039fd75d 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -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 ||
diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c
index 82a33a6829..2e451085be 100644
--- a/src/basic/mountpoint-util.c
+++ b/src/basic/mountpoint-util.c
@@ -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);
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c
index 298f46440f..96364b81ac 100644
--- a/src/basic/stat-util.c
+++ b/src/basic/stat-util.c
@@ -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) {
diff --git a/src/coredump/coredump-vacuum.c b/src/coredump/coredump-vacuum.c
index dcf9cc03cd..c6e201ecf2 100644
--- a/src/coredump/coredump-vacuum.c
+++ b/src/coredump/coredump-vacuum.c
@@ -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);
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index b373c173c1..b5f62ec5e8 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -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;
}
diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c
index 524d10b9d8..80cb0ce622 100644
--- a/src/libsystemd/sd-device/device-monitor.c
+++ b/src/libsystemd/sd-device/device-monitor.c
@@ -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.");
}
}
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 644b9957b0..399e33fa2b 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -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
diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c
index e9785ab964..0a5c775d31 100644
--- a/src/resolve/resolved-resolv-conf.c
+++ b/src/resolve/resolved-resolv-conf.c
@@ -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;
}
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c
index 6e938fc19d..7f88a982bd 100644
--- a/src/shared/mount-util.c
+++ b/src/shared/mount-util.c
@@ -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