]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: fix personality handling
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 10:31:53 +0000 (11:31 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 10:31:53 +0000 (11:31 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c
src/lxc/attach_options.h
src/lxc/confile.c
src/lxc/confile.h

index 3b31a39ed195959db1c3e7ab8663568ec904cdd5..02c36dfe0a16c8cab386442cd91f6fa204249354 100644 (file)
@@ -71,15 +71,24 @@ 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)
+static int get_personality(const char *name, const char *lxcpath,
+                          signed long *personality)
 {
        __do_free char *p = NULL;
+       signed long per;
 
        p = lxc_cmd_get_config_item(name, "lxc.arch", lxcpath);
-       if (!p)
-               return -1;
+       if (!p) {
+               *personality = LXC_ARCH_UNCHANGED;
+               return 0;
+       }
+
+       per = lxc_config_parse_arch(p);
+       if (per == LXC_ARCH_UNCHANGED)
+               return ret_errno(EINVAL);
 
-       return lxc_config_parse_arch(p);
+       *personality = per;
+       return 0;
 }
 
 static int get_attach_context(struct attach_context *ctx,
@@ -127,9 +136,9 @@ 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");
+       ret = get_personality(container->name, container->config_path, &ctx->personality);
+       if (ret)
+               return log_error_errno(ret, errno, "Failed to get personality of the container");
 
        if (!ctx->container->lxc_conf) {
                ctx->container->lxc_conf = lxc_conf_init();
@@ -751,11 +760,13 @@ __noreturn static void do_attach(struct attach_clone_payload *payload)
                else
                        new_personality = options->personality;
 
-               ret = personality(new_personality);
-               if (ret < 0)
-                       goto on_error;
+               if (new_personality != LXC_ARCH_UNCHANGED) {
+                       ret = personality(new_personality);
+                       if (ret < 0)
+                               goto on_error;
 
-               TRACE("Set new personality");
+                       TRACE("Set new personality");
+               }
        }
 #endif
 
index 80fe439103d19f2d9a1e9980bc5a2b6be5808304..3a596fb3051de108e1c7dc5285005821165e510a 100644 (file)
@@ -124,7 +124,7 @@ typedef struct lxc_attach_options_t {
        {                                                                      \
                /* .attach_flags = */   LXC_ATTACH_DEFAULT,                    \
                /* .namespaces = */     -1,                                    \
-               /* .personality = */    -1,                                    \
+               /* .personality = */    0xffffffff,                            \
                /* .initial_cwd = */    NULL,                                  \
                /* .uid = */            (uid_t)-1,                             \
                /* .gid = */            (gid_t)-1,                             \
index 04423871e874028db1b9fb774b218be2fe4fb991..4c93542f98b58715030a160da9908fd6865f8fff 100644 (file)
@@ -3031,7 +3031,7 @@ signed long lxc_config_parse_arch(const char *arch)
                        return pername[i].per;
 #endif
 
-       return -1;
+       return LXC_ARCH_UNCHANGED;
 }
 
 int lxc_fill_elevated_privileges(char *flaglist, int *flags)
index 68d50fc804c598b981c1023f17d7c7d6d222f289..f182dfaf45b86a8b9f6f8ad753c91dc3e232eb33 100644 (file)
@@ -78,7 +78,12 @@ __hidden extern bool lxc_config_define_load(struct lxc_list *defines, struct lxc
 
 __hidden extern void lxc_config_define_free(struct lxc_list *defines);
 
-/* needed for lxc-attach */
+#define LXC_ARCH_UNCHANGED 0xffffffffL
+/*
+ * Parse personality of the container. Returns LXC_ARCH_UNCHANGED if the
+ * personality is not know.
+ * (Used during attach.)
+ */
 __hidden extern signed long lxc_config_parse_arch(const char *arch);
 
 __hidden extern int lxc_fill_elevated_privileges(char *flaglist, int *flags);