]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
rewrite lxc_console_set_stdfds
authorChristian Brauner <christian.brauner@mailbox.org>
Wed, 17 Feb 2016 18:48:54 +0000 (19:48 +0100)
committerChristian Brauner <christian.brauner@mailbox.org>
Sun, 21 Feb 2016 16:04:44 +0000 (17:04 +0100)
Make lxc_console_set_stdfds useable by other callers that do not have access to
lxc_handler.

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
src/lxc/console.c
src/lxc/console.h
src/lxc/start.c

index 7be07b8402f836fcce59445a7fb3a9933854ab80..bdbc20b150253eae6ac0e0814f5015e6aea39f1f 100644 (file)
@@ -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;
 }
 
index 53f5938a17d6fdc823eb86f1260256bf02f925f7..aa6ec7d476a5bbb8b6a6bad024a1e7c4ca79af14 100644 (file)
@@ -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,
index 153b4c418acbbe3a08f43c42cef096f3d231d34d..acf32e4b5dc124cbcf5308379494ffb90bdb9c1c 100644 (file)
@@ -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 */