diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 26ddd03b3..b843c089b 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1093,6 +1093,7 @@ struct lxc_conf *lxc_conf_init(void) new->utsname = NULL; new->tty = 0; new->pts = 0; + new->console.path = NULL; new->console.peer = -1; new->console.master = -1; new->console.slave = -1; diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 822149a43..3a560fda3 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -157,6 +157,7 @@ struct lxc_console { int slave; int master; int peer; + char *path; char name[MAXPATHLEN]; struct termios *tios; }; diff --git a/src/lxc/confile.c b/src/lxc/confile.c index e24cc01ec..80da62540 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -620,7 +620,7 @@ static int config_cap_drop(const char *key, char *value, return ret; } -static int config_console(const char *key, char *value, struct lxc_conf *lxc_conf) +static int _config_console(const char *key, char *value, struct lxc_conf *lxc_conf) { int fd; @@ -635,6 +635,22 @@ static int config_console(const char *key, char *value, struct lxc_conf *lxc_con return 0; } +static int config_console(const char *key, char *value, + struct lxc_conf *lxc_conf) +{ + char *path; + + path = strdup(value); + if (!path) { + SYSERROR("failed to strdup '%s': %m", value); + return -1; + } + + lxc_conf->console.path = path; + + return 0; +} + static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf) { if (strlen(value) >= MAXPATHLEN) { diff --git a/src/lxc/console.c b/src/lxc/console.c index c2bc29bb4..16c5b590c 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -143,6 +143,7 @@ int lxc_create_console(struct lxc_conf *conf) { struct termios tios; struct lxc_console *console = &conf->console; + int fd; if (!conf->rootfs) return 0; @@ -163,6 +164,14 @@ int lxc_create_console(struct lxc_conf *conf) goto err; } + fd = open(console->path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600); + if (fd < 0) { + SYSERROR("failed to open '%s'", console->path); + goto err; + } + + console->peer = fd; + if (!isatty(console->peer)) return 0;