tree-wide: port various places over to new stat_inode_same() helper
This commit is contained in:
+3
-8
@@ -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;
|
||||
|
||||
+1
-2
@@ -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 ||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user