mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
mount-util: teach open_tree_attr_fallback() our usual AT_EMPTY_PATH trick
While at it, rename it to _with_fallback following the naming scheme we use elsewhere.
This commit is contained in:
@@ -824,7 +824,7 @@ static int mount_bind(const char *dest, CustomMount *m, uid_t uid_shift, uid_t u
|
||||
* caller's userns *without* any mount idmapping in place. To get that uid, we clone the
|
||||
* mount source tree and clear any existing idmapping and temporarily mount that tree over
|
||||
* the mount source before we stat the mount source to figure out the source uid. */
|
||||
_cleanup_close_ int fd_clone = open_tree_attr_fallback(
|
||||
_cleanup_close_ int fd_clone = open_tree_attr_with_fallback(
|
||||
AT_FDCWD,
|
||||
m->source,
|
||||
OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC,
|
||||
|
||||
@@ -1441,10 +1441,18 @@ int make_userns(uid_t uid_shift,
|
||||
return TAKE_FD(userns_fd);
|
||||
}
|
||||
|
||||
int open_tree_attr_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr) {
|
||||
int open_tree_attr_with_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
|
||||
assert(attr);
|
||||
|
||||
_cleanup_close_ int fd = open_tree_attr(dir_fd, path, flags, attr, sizeof(struct mount_attr));
|
||||
if (isempty(path)) {
|
||||
path = "";
|
||||
flags |= AT_EMPTY_PATH;
|
||||
}
|
||||
|
||||
fd = open_tree_attr(dir_fd, path, flags, attr, sizeof(struct mount_attr));
|
||||
if (fd >= 0)
|
||||
return TAKE_FD(fd);
|
||||
if (!ERRNO_IS_NOT_SUPPORTED(errno))
|
||||
@@ -1492,8 +1500,8 @@ int remount_idmap_fd(
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
/* Clone the mount point and et the user namespace mapping attribute on the cloned mount point. */
|
||||
mount_fds[n_mounts_fds] = open_tree_attr_fallback(
|
||||
/* dir_fd= */ -EBADF,
|
||||
mount_fds[n_mounts_fds] = open_tree_attr_with_fallback(
|
||||
AT_FDCWD,
|
||||
paths[i],
|
||||
OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC,
|
||||
&(struct mount_attr) {
|
||||
|
||||
@@ -150,7 +150,7 @@ typedef enum RemountIdmapping {
|
||||
_REMOUNT_IDMAPPING_INVALID = -EINVAL,
|
||||
} RemountIdmapping;
|
||||
|
||||
int open_tree_attr_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr);
|
||||
int open_tree_attr_with_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr);
|
||||
|
||||
int make_userns(uid_t uid_shift, uid_t uid_range, uid_t host_owner, uid_t dest_owner, RemountIdmapping idmapping);
|
||||
int remount_idmap_fd(char **p, int userns_fd, uint64_t extra_mount_attr_set);
|
||||
|
||||
Reference in New Issue
Block a user