]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/tty.c
pppd: Check tdb pointer before closing
[ppp.git] / pppd / tty.c
index c356483d1974ee9358010cc585049eddcc1de569..7ece6753a0f3ac19733d556f8b4bbe5b5cc3a7c2 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: tty.c,v 1.25 2006/06/04 07:04:57 paulus Exp $"
+#define RCSID  "$Id: tty.c,v 1.27 2008/07/01 12:27:56 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
+#include <termios.h>
 #include <unistd.h>
 #include <signal.h>
 #include <errno.h>
@@ -82,7 +83,6 @@
 #include <netdb.h>
 #include <utmp.h>
 #include <pwd.h>
-#include <setjmp.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -135,6 +135,7 @@ struct stat devstat;                /* result of stat() on devnam */
 
 /* option variables */
 int    crtscts = 0;            /* Use hardware flow control */
+int    stop_bits = 1;          /* Number of serial port stop bits */
 bool   modem = 1;              /* Use modem control lines */
 int    inspeed = 0;            /* Input/Output speed requested */
 bool   lockflag = 0;           /* Create lock file to lock the serial dev */
@@ -220,6 +221,9 @@ option_t tty_options[] = {
       OPT_PRIOSUB | OPT_ALIAS | OPT_NOARG | OPT_VAL(-1) },
     { "xonxoff", o_special_noarg, (void *)setxonxoff,
       "Set software (XON/XOFF) flow control", OPT_PRIOSUB },
+    { "stop-bits", o_int, &stop_bits,
+      "Number of stop bits in serial port",
+      OPT_PRIO | OPT_PRIVFIX | OPT_LIMITS, NULL, 2, 1 },
 
     { "modem", o_bool, &modem,
       "Use modem control lines", OPT_PRIO | 1 },
@@ -553,7 +557,6 @@ int connect_tty()
         * out and we want to use the modem lines, we reopen it later
         * in order to wait for the carrier detect signal from the modem.
         */
-       hungup = 0;
        got_sigterm = 0;
        connector = doing_callback? callback_script: connect_script;
        if (devnam[0] != 0) {
@@ -688,11 +691,11 @@ int connect_tty()
                        if (device_script(initializer, ttyfd, ttyfd, 0) < 0) {
                                error("Initializer script failed");
                                status = EXIT_INIT_FAILED;
-                               goto errret;
+                               goto errretf;
                        }
                        if (got_sigterm) {
                                disconnect_tty();
-                               goto errret;
+                               goto errretf;
                        }
                        info("Serial port initialized.");
                }
@@ -701,11 +704,11 @@ int connect_tty()
                        if (device_script(connector, ttyfd, ttyfd, 0) < 0) {
                                error("Connect script failed");
                                status = EXIT_CONNECT_FAILED;
-                               goto errret;
+                               goto errretf;
                        }
                        if (got_sigterm) {
                                disconnect_tty();
-                               goto errret;
+                               goto errretf;
                        }
                        info("Serial connection established.");
                }
@@ -754,6 +757,9 @@ int connect_tty()
 
        return ttyfd;
 
+ errretf:
+       if (real_ttyfd >= 0)
+               tcflush(real_ttyfd, TCIOFLUSH);
  errret:
        if (pty_master >= 0) {
                close(pty_master);
@@ -941,7 +947,7 @@ start_charshunt(ifd, ofd)
        exit(0);
     }
     charshunt_pid = cpid;
-    record_child(cpid, "pppd (charshunt)", charshunt_done, NULL);
+    record_child(cpid, "pppd (charshunt)", charshunt_done, NULL, 1);
     return 1;
 }