gentoo: use /var/run for new /run compatibility
[util-vserver.git] / src / vlogin.c
index 56a1df0..9466ad8 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];
@@ -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 */
@@ -209,6 +211,9 @@ void do_vlogin(int argc, char *argv[], int ind)
   /* set terminal to raw mode */
   terminal_raw();
 
+  /* reset terminal to its original mode */
+  atexit(terminal_reset);
+
   /* fork new pseudo terminal */
   if (openpty(&t.fd, &slave, NULL, NULL, NULL) == -1) {
     perror(ENSC_WRAPPERS_PREFIX "openpty()");
@@ -254,9 +259,6 @@ void do_vlogin(int argc, char *argv[], int ind)
 
   strncpy(argv[0], "login", n);
 
-  /* reset terminal to its original mode */
-  atexit(terminal_reset);
-
   /* we want a redraw */
   terminal_redraw();
 
@@ -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 */