2
0
mirror of git://github.com/lxc/lxc synced 2025-08-31 15:47:54 +00:00

file_utils: add open_at_same()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner
2021-07-30 13:02:01 +02:00
parent f6370f2ac2
commit 9910185a80
2 changed files with 18 additions and 0 deletions

View File

@@ -670,6 +670,21 @@ int open_at(int dfd, const char *path, unsigned int o_flags,
return move_fd(fd);
}
int open_at_same(int fd_same, int dfd, const char *path, unsigned int o_flags,
unsigned int resolve_flags, mode_t mode)
{
__do_close int fd = -EBADF;
fd = open_at(dfd, path, o_flags, resolve_flags, mode);
if (fd < 0)
return -errno;
if (!same_file_lax(fd_same, fd))
return ret_errno(EINVAL);
return move_fd(fd);
}
int fd_make_nonblocking(int fd)
{
int flags;

View File

@@ -87,6 +87,9 @@ __hidden extern bool exists_dir_at(int dir_fd, const char *path);
__hidden extern bool exists_file_at(int dir_fd, const char *path);
__hidden extern int open_at(int dfd, const char *path, unsigned int o_flags,
unsigned int resolve_flags, mode_t mode);
__hidden extern int open_at_same(int fd_same, int dfd, const char *path,
unsigned int o_flags,
unsigned int resolve_flags, mode_t mode);
static inline int open_beneath(int dfd, const char *path, unsigned int flags)
{
return open_at(dfd, path, flags, PROTECT_LOOKUP_BENEATH, 0);