Commit 39a78bbe by Christian Brauner

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: 's avatarChristian Brauner <christian.brauner@mailbox.org>
parent 0d4137cc
......@@ -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;
}
......
......@@ -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,
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment