]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-linux.c
try harder to flush the tty output buffer in disestablish_ppp
[ppp.git] / pppd / sys-linux.c
index 33e338d29a46546b761e9e9ea7adf3f4ebc2c9a7..70ba2fa4d34b1f679a044bebc2dc769bcb90f0ee 100644 (file)
@@ -381,10 +381,20 @@ int establish_ppp (int tty_fd)
 
 void disestablish_ppp(int tty_fd)
 {
+    int nout;
+
+    if (!hungup) {
 /*
- * Attempt to restore the previous tty settings
+ * Flush the tty output buffer so that the TIOCSETD doesn't hang.
+ * We may have to do this several times because the tcflush only
+ * affects the serial driver, and may trigger the ppp driver to
+ * supply more data to the serial driver.
  */
-    if (!hungup) {
+       do {
+           if (tcflush(tty_fd, TCIOFLUSH) < 0)
+               break;
+           nout = 0;
+       } while (ioctl(tty_fd, TIOCOUTQ, &nout) >= 0 && nout > 0);
 /*
  * Restore the previous line discipline
  */