]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: use strv_extend() and friends to build directories passed to remount_idmap()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Sep 2024 04:56:33 +0000 (13:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 6 Sep 2024 04:13:15 +0000 (13:13 +0900)
No functional change, just refactoring and preparation for later change.

src/nspawn/nspawn.c

index 92077866a26ec1d8f9e2726bbfabd1cd3477be26..9b8c8973d8a777daa0b73e14f6469529361dd8ac 100644 (file)
@@ -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