From: Christian Brauner Date: Sat, 23 Dec 2017 10:59:36 +0000 (+0100) Subject: console: move pty creation to separate function X-Git-Tag: lxc-3.0.0.beta1~76^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5777fe903040edf470159a75c287649b31df6ce4;p=thirdparty%2Flxc.git console: move pty creation to separate function Signed-off-by: Christian Brauner --- diff --git a/src/lxc/console.c b/src/lxc/console.c index ac7999e4a..a650af6db 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -709,24 +709,13 @@ int lxc_console_create_log_file(struct lxc_console *console) return 0; } -int lxc_console_create(struct lxc_conf *conf) +int lxc_pty_create(struct lxc_console *console) { int ret, saved_errno; - struct lxc_console *console = &conf->console; - - if (!conf->rootfs.path) { - INFO("Container does not have a rootfs. The console will be " - "shared with the host"); - return 0; - } - - if (console->path && !strcmp(console->path, "none")) { - INFO("No console was requested"); - return 0; - } process_lock(); - ret = openpty(&console->master, &console->slave, console->name, NULL, NULL); + ret = openpty(&console->master, &console->slave, console->name, NULL, + NULL); saved_errno = errno; process_unlock(); if (ret < 0) { @@ -752,6 +741,33 @@ int lxc_console_create(struct lxc_conf *conf) goto err; } + return 0; + +err: + lxc_console_delete(console); + return -ENODEV; +} + +int lxc_console_create(struct lxc_conf *conf) +{ + int ret; + struct lxc_console *console = &conf->console; + + if (!conf->rootfs.path) { + INFO("Container does not have a rootfs. The console will be " + "shared with the host"); + return 0; + } + + if (console->path && !strcmp(console->path, "none")) { + INFO("No console was requested"); + return 0; + } + + ret = lxc_pty_create(console); + if (ret < 0) + return -1; + /* create console log file */ ret = lxc_console_create_log_file(console); if (ret < 0) diff --git a/src/lxc/console.h b/src/lxc/console.h index 375349e02..f358437c3 100644 --- a/src/lxc/console.h +++ b/src/lxc/console.h @@ -82,6 +82,12 @@ extern int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttynum) * automatically chowned to the uid/gid of the unprivileged user. For this * ttys_shift_ids() can be called.) */ +extern int lxc_pty_create(struct lxc_console *console); + +/** + * lxc_console_create: Create a new pty. + * - In addition to lxc_pty_create() also sets up all pty logs. + */ extern int lxc_console_create(struct lxc_conf *); /*