From: Yu Watanabe Date: Thu, 5 Sep 2024 04:56:33 +0000 (+0900) Subject: nspawn: use strv_extend() and friends to build directories passed to remount_idmap() X-Git-Tag: v257-rc1~510^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21cd84df6931a358714af9d1f8cc54b26fef1a39;p=thirdparty%2Fsystemd.git nspawn: use strv_extend() and friends to build directories passed to remount_idmap() No functional change, just refactoring and preparation for later change. --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 92077866a26..9b8c8973d8a 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -3993,22 +3993,22 @@ 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; + r = strv_extend(&dirs, directory); + if (r < 0) + return log_oom(); if (dissected_image && dissected_image->partitions[PARTITION_USR].found) { - usr_subtree = path_join(directory, "/usr"); - if (!usr_subtree) + char *s = path_join(directory, "/usr"); + if (!s) return log_oom(); - dirs[i++] = usr_subtree; + r = strv_consume(&dirs, s); + if (r < 0) + return log_oom(); } - dirs[i] = NULL; - 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)) { /* This might fail because the kernel or file system doesn't support idmapping. We