aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tokarev <mjt@tls.msk.ru>2009-11-17 10:56:24 +0100
committerDaniel Lezcano <dlezcano@fr.ibm.com>2009-11-17 10:56:24 +0100
commit92db2bb00ce2acebc0b9818b56238aa5afe313ff (patch)
tree539acef891e940aea5d27e1dcc960d785b9c4769
parenthost consoles/ttys in containers (diff)
downloadlxc-92db2bb00ce2acebc0b9818b56238aa5afe313ff.tar.gz
lxc-92db2bb00ce2acebc0b9818b56238aa5afe313ff.tar.bz2
lxc-92db2bb00ce2acebc0b9818b56238aa5afe313ff.zip
batched reads for lxc_console
Instead of doing I/O one-byte-at-a-time in lxc_console, which is slow, let's do it in batches. Only for output (from container to the host system), since input is most likely one-byte-at-a-time anyway (from a keyboard). Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
-rw-r--r--src/lxc/lxc_console.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c
index 8bdf6b1..d6ba7e4 100644
--- a/src/lxc/lxc_console.c
+++ b/src/lxc/lxc_console.c
@@ -141,7 +141,6 @@ int main(int argc, char *argv[])
/* let's proxy the tty */
for (;;) {
- char c;
struct pollfd pfd[2] = {
{ .fd = 0,
.events = POLLIN|POLLPRI,
@@ -161,6 +160,7 @@ int main(int argc, char *argv[])
/* read the "stdin" and write that to the master
*/
if (pfd[0].revents & POLLIN) {
+ char c;
if (read(0, &c, 1) < 0) {
SYSERROR("failed to read");
goto out_err;
@@ -188,12 +188,14 @@ int main(int argc, char *argv[])
/* read the master and write to "stdout" */
if (pfd[1].revents & POLLIN) {
- if (read(master, &c, 1) < 0) {
+ char buf[1024];
+ int r;
+ r = read(master, buf, sizeof(buf));
+ if (r < 0) {
SYSERROR("failed to read");
goto out_err;
}
- printf("%c", c);
- fflush(stdout);
+ write(1, buf, r);
}
}
out: