X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvlogin.c;h=9466ad85a3380bd00a40671fd614983595681a0b;hb=148ab3024621f97b9cf95091657db2448098bc66;hp=56a1df08a881d01cb99cb18caa16f185273be4dc;hpb=ec17b0fea7ed4c5724abd5db7ce6efb9c500bae5;p=util-vserver.git diff --git a/src/vlogin.c b/src/vlogin.c index 56a1df0..9466ad8 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]; @@ -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 */