From: Daniel Hokka Zakrisson Date: Sun, 18 Mar 2007 15:04:42 +0000 (+0000) Subject: Attempt to fix the endless loop of select() read(). X-Git-Tag: release-0.30.214~91 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f445165a39afe810537571749358d6b4001b01ee;p=util-vserver.git 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 --- 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 */