From: Christian Brauner Date: Sun, 4 Jun 2017 20:33:48 +0000 (+0200) Subject: conf: improve tty shifting function X-Git-Tag: lxc-2.1.0~103^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54117de569032faf57b3cda388d1e4acc3adfcb6;p=thirdparty%2Flxc.git conf: improve tty shifting function Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 7bed9a716..6e6edb193 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3831,16 +3831,21 @@ int chown_mapped_root(char *path, struct lxc_conf *conf) return ret; } -int ttys_shift_ids(struct lxc_conf *c) +int lxc_ttys_shift_ids(struct lxc_conf *c) { if (lxc_list_empty(&c->id_map)) return 0; - if (strcmp(c->console.name, "") !=0 && chown_mapped_root(c->console.name, c) < 0) { - ERROR("Failed to chown %s", c->console.name); + 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; } diff --git a/src/lxc/conf.h b/src/lxc/conf.h index d8d5a6aea..2ba1b4a11 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -472,7 +472,7 @@ extern void lxc_restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf); 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(char *path, struct lxc_conf *conf); -extern int ttys_shift_ids(struct lxc_conf *c); +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 parse_mntopts(const char *mntopts, unsigned long *mntflags, diff --git a/src/lxc/start.c b/src/lxc/start.c index c0a7be5f0..bd1c62697 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -481,7 +481,7 @@ struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char goto out_restore_sigmask; } - if (ttys_shift_ids(conf) < 0) { + if (lxc_ttys_shift_ids(conf) < 0) { ERROR("Failed to shift tty into container."); goto out_restore_sigmask; } diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c index d35ec88c1..c412dbb75 100644 --- a/src/lxc/tools/lxc_attach.c +++ b/src/lxc/tools/lxc_attach.c @@ -315,7 +315,7 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int * conf->console.descr = &descr; /* Shift ttys to container. */ - if (ttys_shift_ids(conf) < 0) { + if (lxc_ttys_shift_ids(conf) < 0) { ERROR("Failed to shift tty into container"); goto err1; }