Attempt to fix the endless loop of select() read().
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Sun, 18 Mar 2007 15:04:42 +0000 (15:04 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Sun, 18 Mar 2007 15:04:42 +0000 (15:04 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2514 94cd875c-1c1d-0410-91d2-eb244daf1a30

src/vlogin.c

index 70a8aed..1d962f4 100644 (file)
@@ -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 */