sync to 0.30.213
[util-vserver.git] / src / vlogin.c
index f42bfd3..ca75719 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: vlogin.c 2325 2006-09-21 19:42:31Z dhozac $
+// $Id: vlogin.c 2525 2007-04-08 00:40:16Z dhozac $
 
 // Copyright (C) 2006 Benedikt Böhm <hollow@gentoo.org>
 // Based on vserver-utils' vlogin program.
@@ -124,7 +124,7 @@ terminal_redraw(void)
 }
 
 /* copy terminal activities */
-static void
+static ssize_t
 terminal_copy(int src, int dst)
 {
   char buf[64];
@@ -137,10 +137,12 @@ terminal_copy(int src, int dst)
     terminal_kill(SIGTERM);
     exit(1);
   } else if (len == -1)
-    return;
+    return -1;
 
   /* 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 */