mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-15 05:57:26 +03:00
fd-util: introduce dir_fd_is_root_or_cwd()
This commit is contained in:
parent
99e6d7941b
commit
e212f42279
@ -162,10 +162,7 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
|
||||
/* If we get AT_FDCWD or dir_fd points to "/", then we always resolve symlinks relative to
|
||||
* the host's root. Hence, CHASE_AT_RESOLVE_IN_ROOT is meaningless. */
|
||||
|
||||
if (dir_fd >= 0)
|
||||
r = dir_fd_is_root(dir_fd);
|
||||
else
|
||||
r = true;
|
||||
r = dir_fd_is_root_or_cwd(dir_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
@ -101,6 +102,9 @@ int read_nr_open(void);
|
||||
int fd_get_diskseq(int fd, uint64_t *ret);
|
||||
|
||||
int dir_fd_is_root(int dir_fd);
|
||||
static inline int dir_fd_is_root_or_cwd(int dir_fd) {
|
||||
return dir_fd == AT_FDCWD ? true : dir_fd_is_root(dir_fd);
|
||||
}
|
||||
|
||||
/* The maximum length a buffer for a /proc/self/fd/<fd> path needs */
|
||||
#define PROC_FD_PATH_MAX \
|
||||
|
@ -444,10 +444,7 @@ int find_esp_and_warn_at(
|
||||
|
||||
assert(rfd >= 0 || rfd == AT_FDCWD);
|
||||
|
||||
if (rfd >= 0)
|
||||
r = dir_fd_is_root(rfd);
|
||||
else
|
||||
r = true;
|
||||
r = dir_fd_is_root_or_cwd(rfd);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
|
||||
if (r == 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user