]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1570] serial clock drivers get outdated input from kernel tty line buffer after...
authorHarlan Stenn <stenn@ntp.org>
Sat, 19 Jun 2010 06:32:32 +0000 (02:32 -0400)
committerHarlan Stenn <stenn@ntp.org>
Sat, 19 Jun 2010 06:32:32 +0000 (02:32 -0400)
bk: 4c1c6480p9KkoYffPgfUrNpHpBdzNQ

ChangeLog
ntpd/ntp_refclock.c

index 0a510f5d0cedfcd396513465bdc2d2eb2fe61500..4fd868def4a89679b7efedc63a355a4dc381871d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 ---
 
+* [Bug 1570] serial clock drivers get outdated input from kernel tty
+  line buffer after startup
 * [Bug 1575] use 'snprintf' with LIB_BUFLENGTH in inttoa.c, tvtoa.c and
   utvtoa.c
 * [Bug 1576] sys/sysctl.h depends on sys/param.h on OpenBSD.
index d299903a8badb80c6de676e543daede50f223db2..125057011612339825d6c90f1cf441910f02d286 100644 (file)
@@ -742,6 +742,9 @@ refclock_open(
 {
        int     fd;
        int     omode;
+#ifdef O_NONBLOCK
+       char    trash[128];     /* litter bin for old input data */
+#endif
 
        /*
         * Open serial port and set default options
@@ -768,6 +771,16 @@ refclock_open(
                close(fd);
                return (0);
        }
+#ifdef O_NONBLOCK
+       /*
+        * We want to make sure there is no pending trash in the input
+        * buffer. Since we have non-blocking IO available, this is a
+        * good moment to read and dump all available outdated stuff
+        * that might have become toxic for the driver.
+        */
+       while (read(fd, trash, sizeof(trash)) > 0 || errno == EINTR)
+               /*NOP*/;
+#endif
        return (fd);
 }
 
@@ -863,6 +876,14 @@ refclock_setup(
                    "refclock_setup fd %d TCSANOW: %m", fd);
                return (0);
        }
+
+       /*
+        * flush input and output buffers to discard any outdated stuff
+        * that might have become toxic for the driver. Failing to do so
+        * is logged, but we keep our fingers crossed otherwise.
+        */
+       if (tcflush(fd, TCIOFLUSH) < 0)
+               msyslog(LOG_ERR, "refclock_setup fd %d tcflush(): %m", fd);
 #endif /* HAVE_TERMIOS */
 
 #ifdef HAVE_SYSV_TTYS