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

index 70db6aabff099005b754eb6b203914da96a19b63..e3d642ebd76c638db0dfc20c58a7bac7ba15e0be 100644 (file)
@@ -71,6 +71,17 @@ static struct attach_context *alloc_attach_context(void)
        return zalloc(sizeof(struct attach_context));
 }
 
+static signed long get_personality(const char *name, const char *lxcpath)
+{
+       __do_free char *p = NULL;
+
+       p = lxc_cmd_get_config_item(name, "lxc.arch", lxcpath);
+       if (!p)
+               return -1;
+
+       return lxc_config_parse_arch(p);
+}
+
 static int get_attach_context(struct attach_context *ctx,
                              struct lxc_container *container)
 {
@@ -116,6 +127,10 @@ static int get_attach_context(struct attach_context *ctx,
        for (int i = 0; i < LXC_NS_MAX; i++)
                ctx->ns_fd[i] = -EBADF;
 
+       ctx->personality = get_personality(container->name, container->config_path);
+       if (ctx->personality < 0)
+               return log_error_errno(-ENOENT, ENOENT, "Failed to get personality of the container");
+
        return 0;
 }
 
@@ -632,17 +647,6 @@ static bool no_new_privs(struct lxc_container *c, lxc_attach_options_t *options)
        return c->set_config_item(c, "lxc.no_new_privs", val);
 }
 
-static signed long get_personality(const char *name, const char *lxcpath)
-{
-       __do_free char *p = NULL;
-
-       p = lxc_cmd_get_config_item(name, "lxc.arch", lxcpath);
-       if (!p)
-               return -1;
-
-       return lxc_config_parse_arch(p);
-}
-
 struct attach_clone_payload {
        int ipc_socket;
        int terminal_pts_fd;
@@ -976,7 +980,6 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
        int i, ret, status;
        char *name, *lxcpath, *new_cwd;
        int ipc_sockets[2];
-       signed long personality;
        pid_t attached_pid, pid, to_cleanup_pid;
        struct attach_context *ctx;
        struct lxc_terminal terminal;
@@ -1011,14 +1014,6 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
                return -1;
        }
 
-       personality = get_personality(name, lxcpath);
-       if (ctx->personality < 0) {
-               ERROR("Failed to get personality of the container");
-               put_attach_context(ctx);
-               return -1;
-       }
-       ctx->personality = personality;
-
        if (!ctx->container->lxc_conf) {
                ctx->container->lxc_conf = lxc_conf_init();
                if (!ctx->container->lxc_conf) {