]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
console: add lxc_pty_map_ids()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 24 Dec 2017 18:13:54 +0000 (19:13 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 9 Jan 2018 12:20:18 +0000 (13:20 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/console.c
src/lxc/console.h
src/lxc/start.c
src/lxc/tools/lxc_attach.c

index 4cab6e74c0d9cd7b589872215398e4606c10ff86..f5bcb9d2411900388f1f693a1eb9fd275ff0ae52 100644 (file)
@@ -3092,24 +3092,6 @@ int chown_mapped_root(const char *path, struct lxc_conf *conf)
        return ret;
 }
 
-int lxc_ttys_shift_ids(struct lxc_conf *c)
-{
-       if (lxc_list_empty(&c->id_map))
-               return 0;
-
-       if (!strcmp(c->console.name, ""))
-               return 0;
-
-       if (chown_mapped_root(c->console.name, c) < 0) {
-               ERROR("failed to chown console \"%s\"", c->console.name);
-               return -1;
-       }
-
-       TRACE("chowned console \"%s\"", c->console.name);
-
-       return 0;
-}
-
 /* NOTE: Must not be called from inside the container namespace! */
 int lxc_create_tmp_proc_mount(struct lxc_conf *conf)
 {
index f75ede86ce9a3f49d4748357e09ae71c6e6c30a5..1146a1d4f67cbf6ee721d772b0d58ea12c0e5d8b 100644 (file)
@@ -452,7 +452,6 @@ extern int find_unmapped_nsid(struct lxc_conf *conf, enum idtype idtype);
 extern int mapped_hostid(unsigned id, struct lxc_conf *conf,
                         enum idtype idtype);
 extern int chown_mapped_root(const char *path, struct lxc_conf *conf);
-extern int lxc_ttys_shift_ids(struct lxc_conf *c);
 extern int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
                         const char *fn_name);
 extern int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *),
index 2f107b5e61570b39c6856db6232309c804512b5b..3feca832e623019b1f95047eac88dbee24e5c7fb 100644 (file)
@@ -1038,3 +1038,25 @@ void lxc_pty_conf_free(struct lxc_console *console)
        if (console->buffer_size > 0 && console->ringbuf.addr)
                lxc_ringbuf_release(&console->ringbuf);
 }
+
+int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_console *pty)
+{
+       int ret;
+
+       if (lxc_list_empty(&c->id_map))
+               return 0;
+
+       ret = strcmp(pty->name, "");
+       if (ret == 0)
+               return 0;
+
+       ret = chown_mapped_root(pty->name, c);
+       if (ret < 0) {
+               ERROR("Failed to chown \"%s\"", pty->name);
+               return -1;
+       }
+
+       TRACE("Chowned \"%s\"", pty->name);
+
+       return 0;
+}
index b456746e484e7602f271bb02480920a69c810eec..a385ed1f7fa9bd696d187f7de84e629732c6c299 100644 (file)
@@ -237,5 +237,6 @@ extern int lxc_login_pty(int fd);
 extern void lxc_pty_conf_free(struct lxc_console *console);
 extern void lxc_pty_info_init(struct lxc_pty_info *pty);
 extern void lxc_pty_init(struct lxc_console *pty);
+extern int lxc_pty_map_ids(struct lxc_conf *c, struct lxc_console *pty);
 
 #endif
index c12728d613864b26679b2fb39132f8da04ae97ca..5a5556d86e4676b128337f01cd6a5f08793cd960 100644 (file)
@@ -757,7 +757,8 @@ int lxc_init(const char *name, struct lxc_handler *handler)
        }
        TRACE("Created console");
 
-       if (lxc_ttys_shift_ids(conf) < 0) {
+       ret = lxc_pty_map_ids(conf, &conf->console);
+       if (ret < 0) {
                ERROR("Failed to shift tty into container.");
                goto out_restore_sigmask;
        }
index b5c89270c1f2ed595568a02ba1e95909c3ded493..0615cc719a9fc14479e80a208222999d79f8d9d6 100644 (file)
@@ -338,7 +338,8 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
        conf->console.descr = &descr;
 
        /* Shift ttys to container. */
-       if (lxc_ttys_shift_ids(conf) < 0) {
+       ret = lxc_pty_map_ids(conf, &conf->console);
+       if (ret < 0) {
                fprintf(stderr, "Failed to shift tty into container\n");
                goto err1;
        }