basic/path-util: allow flags for path_equal_or_files_same
No functional change, just a new parameters and the tests that AT_SYMLINK_NOFOLLOW works as expected.
This commit is contained in:
@@ -442,8 +442,8 @@ bool path_equal(const char *a, const char *b) {
|
||||
return path_compare(a, b) == 0;
|
||||
}
|
||||
|
||||
bool path_equal_or_files_same(const char *a, const char *b) {
|
||||
return path_equal(a, b) || files_same(a, b) > 0;
|
||||
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;
|
||||
}
|
||||
|
||||
char* path_join(const char *root, const char *path, const char *rest) {
|
||||
|
||||
@@ -46,7 +46,7 @@ char* path_kill_slashes(char *path);
|
||||
char* path_startswith(const char *path, const char *prefix) _pure_;
|
||||
int path_compare(const char *a, const char *b) _pure_;
|
||||
bool path_equal(const char *a, const char *b) _pure_;
|
||||
bool path_equal_or_files_same(const char *a, const char *b);
|
||||
bool path_equal_or_files_same(const char *a, const char *b, int flags);
|
||||
char* path_join(const char *root, const char *path, const char *rest);
|
||||
|
||||
static inline bool path_equal_ptr(const char *a, const char *b) {
|
||||
|
||||
@@ -807,7 +807,7 @@ int pid_from_same_root_fs(pid_t pid) {
|
||||
|
||||
root = procfs_file_alloca(pid, "root");
|
||||
|
||||
return files_same(root, "/proc/1/root");
|
||||
return files_same(root, "/proc/1/root", 0);
|
||||
}
|
||||
|
||||
bool is_main_thread(void) {
|
||||
|
||||
+1
-1
@@ -182,7 +182,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, "/")) {
|
||||
if (path_equal_or_files_same(path, "/", 0)) {
|
||||
log_error("Attempted to remove entire root file system, and we can't allow that.");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
@@ -412,7 +412,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))
|
||||
if (!path_equal_or_files_same(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, 0))
|
||||
return false;
|
||||
} else {
|
||||
if (a->size != b->size)
|
||||
|
||||
@@ -169,16 +169,16 @@ int path_is_os_tree(const char *path) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int files_same(const char *filea, const char *fileb) {
|
||||
int files_same(const char *filea, const char *fileb, int flags) {
|
||||
struct stat a, b;
|
||||
|
||||
assert(filea);
|
||||
assert(fileb);
|
||||
|
||||
if (stat(filea, &a) < 0)
|
||||
if (fstatat(AT_FDCWD, filea, &a, flags) < 0)
|
||||
return -errno;
|
||||
|
||||
if (stat(fileb, &b) < 0)
|
||||
if (fstatat(AT_FDCWD, fileb, &b, flags) < 0)
|
||||
return -errno;
|
||||
|
||||
return a.st_dev == b.st_dev &&
|
||||
|
||||
@@ -49,7 +49,7 @@ int null_or_empty_fd(int fd);
|
||||
int path_is_read_only_fs(const char *path);
|
||||
int path_is_os_tree(const char *path);
|
||||
|
||||
int files_same(const char *filea, const char *fileb);
|
||||
int files_same(const char *filea, const char *fileb, int flags);
|
||||
|
||||
/* The .f_type field of struct statfs is really weird defined on
|
||||
* different archs. Let's give its type a name. */
|
||||
|
||||
+1
-1
@@ -541,7 +541,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
|
||||
if (asprintf(&userns_fd_path, "/proc/self/fd/%d", userns_fd) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
r = files_same(userns_fd_path, "/proc/self/ns/user");
|
||||
r = files_same(userns_fd_path, "/proc/self/ns/user", 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r)
|
||||
|
||||
+1
-1
@@ -574,7 +574,7 @@ int running_in_chroot(void) {
|
||||
if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0)
|
||||
return 0;
|
||||
|
||||
ret = files_same("/proc/1/root", "/");
|
||||
ret = files_same("/proc/1/root", "/", 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user