]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
refclock_parse.c:
authorFrank Kardel <kardel@ntp.org>
Mon, 1 May 2006 18:27:54 +0000 (18:27 +0000)
committerFrank Kardel <kardel@ntp.org>
Mon, 1 May 2006 18:27:54 +0000 (18:27 +0000)
  If an input buffer parses into more than one message do insert the
  parsed message in a new input buffer instead of processing it
  directly. This avoids deed complicated processing in signal
  handling.
ntpd.c:
  re-instate vital io blocking protocol to insure
  that receive buffer queue is only manipulated when
  io is blocked
recvbuff.c:
  cleanup get_full_recvbuffer() to decide only the full queue head
  and simplify code (remove multiple tests)

bk: 4456532azzBoAh68r882nkN116YYlA

libntp/recvbuff.c
ntpd/ntpd.c
ntpd/refclock_parse.c

index 2c274d4c8bae3b6f6b898ab367bc2189540334a4..103913d5274e1da3f27a34d894a1ea6ec7b9f91b 100644 (file)
@@ -175,16 +175,11 @@ get_full_recv_buffer(void)
 {
        recvbuf_t *rbuf;
 
-       if (0 == full_recvbufs)
-           return 0;
-
+       LOCK();
 #ifdef DEBUG
        if (debug > 1 && full_recvbufs)
            printf("get_full_recv_buffer() called and full_recvbufs is %lu\n", full_recvbufs);
 #endif
-       if (0 == full_recvbufs)
-           msyslog(LOG_ERR, "get_full_recv_buffer() called but full_recvbufs is 0!");
-       LOCK();
        rbuf = ISC_LIST_HEAD(full_list);
        if (rbuf != NULL)
        {
@@ -193,12 +188,10 @@ get_full_recv_buffer(void)
        }
        else
        {
-               if (full_recvbufs)
+               if (full_recvbufs) {
                    msyslog(LOG_ERR, "get_full_recv_buffer: full_list is empty but full_recvbufs is %lu!", full_recvbufs);
-               /*
-                * Make sure we reset the full count to 0
-                */
-               full_recvbufs = 0;
+                   abort();
+               }
        }
        UNLOCK();
        return (rbuf);
index 3bd68ffb5b3f8bb6c32cc824021d91e73f043506..2231614748ad0b42295030a801ee55fef7e35197 100644 (file)
@@ -889,14 +889,13 @@ getgroup:
                block_io_and_alarm();
 # endif
 
-               tot_full_recvbufs = full_recvbuffs();   /* get received buffers */
                if (alarm_flag)         /* alarmed? */
                {
                        was_alarmed = 1;
                        alarm_flag = 0;
                }
 
-               if (!was_alarmed && tot_full_recvbufs == 0)
+               if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE)
                {
                        /*
                         * Nothing to do.  Wait for something.
@@ -939,42 +938,56 @@ getgroup:
                                was_alarmed = 1;
                                alarm_flag = 0;
                        }
-                       tot_full_recvbufs = full_recvbuffs();  /* get received buffers */
                }
-# ifdef HAVE_SIGNALED_IO
-               unblock_io_and_alarm();
-# endif /* HAVE_SIGNALED_IO */
 
-               /*
-                * Out here, signals are unblocked.  Call timer routine
-                * to process expiry.
-                */
                if (was_alarmed)
                {
+# ifdef HAVE_SIGNALED_IO
+                       unblock_io_and_alarm();
+# endif /* HAVE_SIGNALED_IO */
+                       /*
+                        * Out here, signals are unblocked.  Call timer routine
+                        * to process expiry.
+                        */
                        timer();
                        was_alarmed = 0;
+# ifdef HAVE_SIGNALED_IO
+                        block_io_and_alarm();
+# endif /* HAVE_SIGNALED_IO */
                }
 
 #endif /* HAVE_IO_COMPLETION_PORT */
 
-               while (full_recvbuffs())
+               rbuf = get_full_recv_buffer();
+               while (rbuf != NULL)
                {
+# ifdef HAVE_SIGNALED_IO
+                       unblock_io_and_alarm();
+# endif /* HAVE_SIGNALED_IO */
                        /*
                         * Call the data procedure to handle each received
                         * packet.
                         */
-                       rbuf = get_full_recv_buffer();
                        if (rbuf != NULL)       /* This should always be true */
                        {
                                (rbuf->receiver)(rbuf);
                                freerecvbuf(rbuf);
+                       } else {
+                                msyslog(LOG_ERR, "receive buffer corruption - receiver found to be NULL - ABORTING");
+                                abort();
                        }
+# ifdef HAVE_SIGNALED_IO
+                        block_io_and_alarm();
+# endif /* HAVE_SIGNALED_IO */
                }
 
                /*
                 * Go around again
                 */
        }
+# ifdef HAVE_SIGNALED_IO
+       unblock_io_and_alarm();
+# endif /* HAVE_SIGNALED_IO */
        return 1;
 }
 
index 04cbb876673e2e4195e534db3beb75c09ea7be2b..6937dbb414cd4446b9072f3dad59e76c8f9a2b2b 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * /src/NTP/REPOSITORY/ntp4-dev/ntpd/refclock_parse.c,v 4.66 2006/03/18 00:45:30 kardel RELEASE_20060318_A
+ * /src/NTP/REPOSITORY/ntp4-dev/ntpd/refclock_parse.c,v 4.68 2006/05/01 17:02:51 kardel RELEASE_20060501_A
  *
- * refclock_parse.c,v 4.66 2006/03/18 00:45:30 kardel RELEASE_20060318_A
+ * refclock_parse.c,v 4.68 2006/05/01 17:02:51 kardel RELEASE_20060501_A
  *
  * generic reference clock driver for several DCF/GPS/MSF/... receivers
  *
 #include "binio.h"
 #include "ascii.h"
 #include "ieee754io.h"
+#include "recvbuff.h"
 
-static char rcsid[] = "refclock_parse.c,v 4.66 2006/03/18 00:45:30 kardel RELEASE_20060318_A";
+static char rcsid[] = "refclock_parse.c,v 4.68 2006/05/01 17:02:51 kardel RELEASE_20060501_A";
 
 /**===========================================================================
  ** external interface to ntp mechanism
@@ -2020,7 +2021,7 @@ local_input(
        {
                if (parse_ioread(&parse->parseio, (unsigned int)(*s++), &ts))
                {
-                       struct recvbuf buf;
+                       struct recvbuf *buf;
 
                        /*
                         * got something good to eat
@@ -2171,20 +2172,25 @@ local_input(
 #endif /* TIOCDCDTIMESTAMP */
 #endif /* HAVE_PPSAPI */
                        }
-                       if (count)
-                       {       /* simulate receive */
-                               memmove((caddr_t)buf.recv_buffer,
-                                       (caddr_t)&parse->parseio.parse_dtime,
-                                       sizeof(parsetime_t));
-                               parse_iodone(&parse->parseio);
-                               buf.recv_length = sizeof(parsetime_t);
-                               buf.recv_time = rbufp->recv_time;
-                               buf.srcadr = rbufp->srcadr;
-                               buf.dstadr = rbufp->dstadr;
-                               buf.fd     = rbufp->fd;
-                               buf.X_from_where = rbufp->X_from_where;
-                               rbufp->receiver(&buf);
-                       }
+
+                       if (count)
+                       {       /* simulate receive */
+                               buf = get_free_recv_buffer();
+                               if (buf != NULL) {
+                                       memmove((caddr_t)buf->recv_buffer,
+                                               (caddr_t)&parse->parseio.parse_dtime,
+                                               sizeof(parsetime_t));
+                                       buf->recv_length  = sizeof(parsetime_t);
+                                       buf->recv_time    = rbufp->recv_time;
+                                       buf->srcadr       = rbufp->srcadr;
+                                       buf->dstadr       = rbufp->dstadr;
+                                       buf->receiver     = rbufp->receiver;
+                                       buf->fd           = rbufp->fd;
+                                       buf->X_from_where = rbufp->X_from_where;
+                                       add_full_recv_buffer(buf);
+                               }
+                               parse_iodone(&parse->parseio);
+                       }
                        else
                        {
                                memmove((caddr_t)rbufp->recv_buffer,
@@ -5672,6 +5678,15 @@ int refclock_parse_bs;
  * History:
  *
  * refclock_parse.c,v
+ * Revision 4.68  2006/05/01 17:02:51  kardel
+ * copy receiver method also for newlwy created receive buffers
+ *
+ * Revision 4.67  2006/05/01 14:37:29  kardel
+ * If an input buffer parses into more than one message do insert the
+ * parsed message in a new input buffer instead of processing it
+ * directly. This avoids deed complicated processing in signal
+ * handling.
+ *
  * Revision 4.66  2006/03/18 00:45:30  kardel
  * coverity fixes found in NetBSD coverity scan
  *