From: Christian Brauner Date: Wed, 17 Feb 2016 18:48:54 +0000 (+0100) Subject: rewrite lxc_console_set_stdfds X-Git-Tag: lxc-2.0.0.rc2~5^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39a78bbef05ed240e62fe4863a5d629de9808ea6;p=thirdparty%2Flxc.git rewrite lxc_console_set_stdfds Make lxc_console_set_stdfds useable by other callers that do not have access to lxc_handler. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/console.c b/src/lxc/console.c index 7be07b840..bdbc20b15 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -598,21 +598,29 @@ err: return -1; } -int lxc_console_set_stdfds(struct lxc_handler *handler) +int lxc_console_set_stdfds(int fd) { - struct lxc_conf *conf = handler->conf; - struct lxc_console *console = &conf->console; - - if (console->slave < 0) + if (fd < 0) return 0; - if (dup2(console->slave, 0) < 0 || - dup2(console->slave, 1) < 0 || - dup2(console->slave, 2) < 0) - { - SYSERROR("failed to dup console"); - return -1; - } + if (isatty(STDIN_FILENO)) + if (dup2(fd, STDIN_FILENO) < 0) { + SYSERROR("failed to duplicate stdin."); + return -1; + } + + if (isatty(STDOUT_FILENO)) + if (dup2(fd, STDOUT_FILENO) < 0) { + SYSERROR("failed to duplicate stdout."); + return -1; + } + + if (isatty(STDERR_FILENO)) + if (dup2(fd, STDERR_FILENO) < 0) { + SYSERROR("failed to duplicate stderr."); + return -1; + } + return 0; } diff --git a/src/lxc/console.h b/src/lxc/console.h index 53f5938a1..aa6ec7d47 100644 --- a/src/lxc/console.h +++ b/src/lxc/console.h @@ -55,7 +55,7 @@ extern int lxc_console(struct lxc_container *c, int ttynum, int escape); extern int lxc_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd); -extern int lxc_console_set_stdfds(struct lxc_handler *); +extern int lxc_console_set_stdfds(int fd); extern int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr); extern int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata, diff --git a/src/lxc/start.c b/src/lxc/start.c index 153b4c418..acf32e4b5 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -798,7 +798,7 @@ static int do_start(void *data) * setup on its console ie. the pty allocated in lxc_console_create() * so make sure that that pty is stdin,stdout,stderr. */ - if (lxc_console_set_stdfds(handler) < 0) + if (lxc_console_set_stdfds(handler->conf->console.slave) < 0) goto out_warn_father; /* If we mounted a temporary proc, then unmount it now */