console: cleanup

parent 76f61234
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
#include <../include/openpty.h> #include <../include/openpty.h>
#endif #endif
#define LXC_CONSOLE_BUFFER_SIZE 1024
lxc_log_define(console, lxc); lxc_log_define(console, lxc);
static struct lxc_list lxc_ttys; static struct lxc_list lxc_ttys;
...@@ -206,12 +208,12 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data, ...@@ -206,12 +208,12 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct lxc_console *console = (struct lxc_console *)data; struct lxc_console *console = (struct lxc_console *)data;
char buf[1024]; char buf[LXC_CONSOLE_BUFFER_SIZE];
int r, w; int r, w, w_log;
w = r = lxc_read_nointr(fd, buf, sizeof(buf)); w = r = lxc_read_nointr(fd, buf, sizeof(buf));
if (r <= 0) { 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); lxc_mainloop_del_handler(descr, fd);
if (fd == console->peer) { if (fd == console->peer) {
if (console->tty_state) { if (console->tty_state) {
...@@ -229,16 +231,22 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data, ...@@ -229,16 +231,22 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
if (fd == console->peer) if (fd == console->peer)
w = lxc_write_nointr(console->master, buf, r); w = lxc_write_nointr(console->master, buf, r);
w_log = 0;
if (fd == console->master) { if (fd == console->master) {
if (console->log_fd >= 0) /* write to peer first */
w = lxc_write_nointr(console->log_fd, buf, r);
if (console->peer >= 0) if (console->peer >= 0)
w = lxc_write_nointr(console->peer, buf, r); 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) 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; return 0;
} }
...@@ -721,7 +729,7 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata, ...@@ -721,7 +729,7 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct lxc_tty_state *ts = cbdata; struct lxc_tty_state *ts = cbdata;
char buf[1024]; char buf[LXC_CONSOLE_BUFFER_SIZE];
int r, w; int r, w;
if (fd != ts->masterfd) if (fd != ts->masterfd)
......
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