/* Attach the idmapped mount. */
if (is_private) {
+ unsigned int mmflags = MOVE_MOUNT_F_EMPTY_PATH;
+
/* Unmount the old, non-idmapped mount we just cloned and idmapped. */
umount2(target, MNT_DETACH);
- rc = move_mount(fd_tree, "", -1, target, MOVE_MOUNT_F_EMPTY_PATH);
+ if (mnt_context_target_fd_required(cxt)) {
+ int fd_tgt = mnt_context_get_target_fd(cxt);
+
+ if (fd_tgt < 0) {
+ rc = -errno;
+ goto done;
+ }
+ mmflags |= MOVE_MOUNT_T_EMPTY_PATH;
+ rc = move_mount(fd_tree, "", fd_tgt, "", mmflags);
+ } else
+ rc = move_mount(fd_tree, "", AT_FDCWD, target, mmflags);
+
+ if (rc == 0)
+ rc = mnt_context_reopen_target_fd(cxt);
if (rc < 0) {
mnt_context_syscall_save_status(cxt, "move_mount", 0);
if (!mnt_context_read_mesgs(cxt, fd_tree)) {