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;
}
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,
* 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 */