Flush the tty when welcomer or connector fails
authorPaul Mackerras <paulus@samba.org>
Mon, 23 Jun 2008 11:44:06 +0000 (11:44 +0000)
committerPaul Mackerras <paulus@samba.org>
Mon, 23 Jun 2008 11:44:06 +0000 (11:44 +0000)
This avoids having the tcsetsf and the close of the tty device block
for long periods waiting for output to drain, as can happen if for
instance the serial port is in CRTSCTS mode and CTS is negated.

pppd/tty.c

index c356483d1974ee9358010cc585049eddcc1de569..a9832d918d076a0bd8634091d9086269c353de1f 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.26 2008/06/23 11:44:06 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>
@@ -688,11 +689,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 +702,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 +755,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 +945,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;
 }