]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
console: cleanup
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 19 Jan 2018 14:36:14 +0000 (15:36 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 19 Jan 2018 14:36:14 +0000 (15:36 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/console.c

index 40cc1fae53fc902c5be9904e02a780e83c841c8f..acb5ac471ae12cd0e276f1a6fd78773ff98b799d 100644 (file)
@@ -51,6 +51,8 @@
 #include <../include/openpty.h>
 #endif
 
+#define LXC_CONSOLE_BUFFER_SIZE 1024
+
 lxc_log_define(console, lxc);
 
 static struct lxc_list lxc_ttys;
@@ -206,12 +208,12 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
                       struct lxc_epoll_descr *descr)
 {
        struct lxc_console *console = (struct lxc_console *)data;
-       char buf[1024];
-       int r, w;
+       char buf[LXC_CONSOLE_BUFFER_SIZE];
+       int r, w, w_log;
 
        w = r = lxc_read_nointr(fd, buf, sizeof(buf));
        if (r <= 0) {
-               INFO("console client on fd %d has exited", fd);
+               INFO("Console client on fd %d has exited", fd);
                lxc_mainloop_del_handler(descr, fd);
                if (fd == console->peer) {
                        if (console->tty_state) {
@@ -229,16 +231,22 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
        if (fd == console->peer)
                w = lxc_write_nointr(console->master, buf, r);
 
+       w_log = 0;
        if (fd == console->master) {
-               if (console->log_fd >= 0)
-                       w = lxc_write_nointr(console->log_fd, buf, r);
-
+               /* write to peer first */
                if (console->peer >= 0)
                        w = lxc_write_nointr(console->peer, buf, r);
+
+               /* write to console log */
+               if (console->log_fd >= 0)
+                       w_log = lxc_write_nointr(console->log_fd, buf, r);
        }
 
        if (w != r)
-               WARN("console short write r:%d w:%d", r, w);
+               WARN("Console short write r:%d != w:%d", r, w);
+
+       if (w_log < 0)
+               TRACE("Failed to write %d bytes to console log", r);
 
        return 0;
 }
@@ -721,7 +729,7 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
                struct lxc_epoll_descr *descr)
 {
        struct lxc_tty_state *ts = cbdata;
-       char buf[1024];
+       char buf[LXC_CONSOLE_BUFFER_SIZE];
        int r, w;
 
        if (fd != ts->masterfd)