]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: move config init into get_attach_context()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 28 Jan 2021 17:59:55 +0000 (18:59 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 28 Jan 2021 18:18:31 +0000 (19:18 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c

index e3d642ebd76c638db0dfc20c58a7bac7ba15e0be..f44147d249fba804c123b4efddc4c8c96a044b32 100644 (file)
@@ -131,6 +131,12 @@ static int get_attach_context(struct attach_context *ctx,
        if (ctx->personality < 0)
                return log_error_errno(-ENOENT, ENOENT, "Failed to get personality of the container");
 
+       if (!ctx->container->lxc_conf) {
+               ctx->container->lxc_conf = lxc_conf_init();
+               if (!ctx->container->lxc_conf)
+                       return log_error_errno(-ENOMEM, ENOMEM, "Failed to allocate new lxc config");
+       }
+
        return 0;
 }
 
@@ -1014,18 +1020,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
                return -1;
        }
 
-       if (!ctx->container->lxc_conf) {
-               ctx->container->lxc_conf = lxc_conf_init();
-               if (!ctx->container->lxc_conf) {
-                       put_attach_context(ctx);
-                       return -1;
-               }
-       }
        conf = ctx->container->lxc_conf;
-       if (!conf) {
-               put_attach_context(ctx);
-               return log_error_errno(-EINVAL, EINVAL, "Missing container confifg");
-       }
 
        if (!fetch_seccomp(ctx->container, options))
                WARN("Failed to get seccomp policy");