From f445165a39afe810537571749358d6b4001b01ee Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 18 Mar 2007 15:04:42 +0000 Subject: [PATCH] Attempt to fix the endless loop of select() read(). git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2514 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- src/vlogin.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/vlogin.c b/src/vlogin.c index 70a8aed..1d962f4 100644 --- a/src/vlogin.c +++ b/src/vlogin.c @@ -124,7 +124,7 @@ terminal_redraw(void) } /* copy terminal activities */ -static void +static ssize_t terminal_copy(int src, int dst) { char buf[64]; @@ -141,6 +141,8 @@ terminal_copy(int src, int dst) /* write activity to user */ EwriteAll(dst, buf, len); + + return len; } /* shuffle all output, and reset the terminal */ @@ -276,11 +278,21 @@ void do_vlogin(int argc, char *argv[], int ind) exit(wrapper_exit_code); } - if (FD_ISSET(STDIN_FILENO, &rfds)) - terminal_copy(STDIN_FILENO, t.fd); + if (FD_ISSET(STDIN_FILENO, &rfds)) { + /* EOF */ + if (terminal_copy(STDIN_FILENO, t.fd) == 0) { + terminal_kill(SIGHUP); + exit(0); + } + } - if (FD_ISSET(t.fd, &rfds)) - terminal_copy(t.fd, STDOUT_FILENO); + if (FD_ISSET(t.fd, &rfds)) { + /* EOF */ + if (terminal_copy(t.fd, STDOUT_FILENO) == 0) { + terminal_kill(SIGHUP); + exit(0); + } + } } /* never get here, signal handler exits */ -- 1.8.1.5