Merge pull request #34258 from yuwata/nspawn-volatile-u

nspawn: make --volatile work with -U
This commit is contained in:
Lennart Poettering
2024-09-09 17:11:11 +02:00
committed by GitHub
4 changed files with 89 additions and 15 deletions
+22 -11
View File
@@ -4083,21 +4083,24 @@ static int outer_child(
if (arg_userns_mode != USER_NAMESPACE_NO &&
IN_SET(arg_userns_ownership, USER_NAMESPACE_OWNERSHIP_MAP, USER_NAMESPACE_OWNERSHIP_AUTO) &&
arg_uid_shift != 0) {
_cleanup_free_ char *usr_subtree = NULL;
char *dirs[3];
size_t i = 0;
_cleanup_strv_free_ char **dirs = NULL;
dirs[i++] = (char*) directory;
if (dissected_image && dissected_image->partitions[PARTITION_USR].found) {
usr_subtree = path_join(directory, "/usr");
if (!usr_subtree)
if (arg_volatile_mode != VOLATILE_YES) {
r = strv_extend(&dirs, directory);
if (r < 0)
return log_oom();
dirs[i++] = usr_subtree;
}
dirs[i] = NULL;
if ((dissected_image && dissected_image->partitions[PARTITION_USR].found) ||
arg_volatile_mode == VOLATILE_YES) {
char *s = path_join(directory, "/usr");
if (!s)
return log_oom();
r = strv_consume(&dirs, s);
if (r < 0)
return log_oom();
}
r = remount_idmap(dirs, arg_uid_shift, arg_uid_range, UID_INVALID, UID_INVALID, REMOUNT_IDMAPPING_HOST_ROOT);
if (r == -EINVAL || ERRNO_IS_NEG_NOT_SUPPORTED(r)) {
@@ -4118,6 +4121,14 @@ static int outer_child(
}
}
r = setup_volatile_mode_after_remount_idmap(
directory,
arg_volatile_mode,
arg_uid_shift,
arg_selinux_apifs_context);
if (r < 0)
return r;
if (dissected_image) {
/* Now we know the uid shift, let's now mount everything else that might be in the image. */
r = dissected_image_mount_and_warn(