X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Ftty.c;h=1ef8a52eacae3bf8a6560005c2659214e1186622;hp=30d476559f6c32a3604f5495d90a4a54ac9ab005;hb=5628c6cdf469989897d40a1820d725806a1fcbf2;hpb=6b5081d8af903c5a7e3c4f30cd6c4afd9f5b658f diff --git a/pppd/tty.c b/pppd/tty.c index 30d4765..1ef8a52 100644 --- a/pppd/tty.c +++ b/pppd/tty.c @@ -68,7 +68,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: tty.c,v 1.19 2004/11/06 05:42:29 paulus Exp $" +#define RCSID "$Id: tty.c,v 1.24 2005/07/12 01:09:05 paulus Exp $" #include #include @@ -152,6 +152,8 @@ int using_pty = 0; /* we're allocating a pty as the device */ extern uid_t uid; extern int kill_link; +extern int asked_to_quit; +extern int got_sigterm; /* XXX */ extern int privopen; /* don't lock, open device as root */ @@ -443,7 +445,12 @@ tty_check_options() struct stat statbuf; int fdflags; - if (demand && connect_script == 0) { + if (demand && notty) { + option_error("demand-dialling is incompatible with notty"); + exit(EXIT_OPTION_ERROR); + } + if (demand && connect_script == 0 && ptycommand == NULL + && pty_socket == NULL) { option_error("connect script is required for demand-dialling\n"); exit(EXIT_OPTION_ERROR); } @@ -547,7 +554,7 @@ int connect_tty() * in order to wait for the carrier detect signal from the modem. */ hungup = 0; - kill_link = 0; + got_sigterm = 0; connector = doing_callback? callback_script: connect_script; if (devnam[0] != 0) { for (;;) { @@ -644,6 +651,12 @@ int connect_tty() } else if (notty) { if (!start_charshunt(0, 1)) goto errret; + dup2(fd_devnull, 0); + dup2(fd_devnull, 1); + if (log_to_fd == 1) + log_to_fd = -1; + if (log_to_fd != 2) + dup2(fd_devnull, 2); } else if (record_file != NULL) { int fd = dup(ttyfd); if (!start_charshunt(fd, fd)) @@ -673,7 +686,7 @@ int connect_tty() status = EXIT_INIT_FAILED; goto errret; } - if (kill_link) { + if (got_sigterm) { disconnect_tty(); goto errret; } @@ -686,7 +699,7 @@ int connect_tty() status = EXIT_CONNECT_FAILED; goto errret; } - if (kill_link) { + if (got_sigterm) { disconnect_tty(); goto errret; } @@ -712,7 +725,7 @@ int connect_tty() error("Failed to reopen %s: %m", devnam); status = EXIT_OPEN_FAILED; } - if (!persist || errno != EINTR || hungup || kill_link) + if (!persist || errno != EINTR || hungup || got_sigterm) goto errret; } close(i); @@ -732,7 +745,7 @@ int connect_tty() * time for something from the peer. This can avoid bouncing * our packets off his tty before he has it set up. */ - if (connector != NULL || ptycommand != NULL) + if (connector != NULL || ptycommand != NULL || pty_socket != NULL) listen_time = connect_delay; return ttyfd; @@ -742,15 +755,9 @@ int connect_tty() close(pty_master); pty_master = -1; } - if (pty_slave >= 0) { - close(pty_slave); - pty_slave = -1; - } - if (real_ttyfd >= 0) { - close(real_ttyfd); - real_ttyfd = -1; - } ttyfd = -1; + if (got_sigterm) + asked_to_quit = 1; return -1; } @@ -766,6 +773,7 @@ void disconnect_tty() } else { info("Serial link disconnected."); } + stop_charshunt(NULL, 0); } void tty_close_fds() @@ -929,7 +937,6 @@ start_charshunt(ifd, ofd) exit(0); } charshunt_pid = cpid; - add_notifier(&sigreceived, stop_charshunt, 0); record_child(cpid, "pppd (charshunt)", charshunt_done, NULL); return 1; }