From: Frank Kardel Date: Mon, 1 May 2006 18:27:54 +0000 (+0000) Subject: refclock_parse.c: X-Git-Tag: NTP_4_2_1P242_RC~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4461b821c583abf6643da93a0ef7b870c8ed0e2a;p=thirdparty%2Fntp.git refclock_parse.c: 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 --- diff --git a/libntp/recvbuff.c b/libntp/recvbuff.c index 2c274d4c8..103913d52 100644 --- a/libntp/recvbuff.c +++ b/libntp/recvbuff.c @@ -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); diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 3bd68ffb5..223161474 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -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; } diff --git a/ntpd/refclock_parse.c b/ntpd/refclock_parse.c index 04cbb8766..6937dbb41 100644 --- a/ntpd/refclock_parse.c +++ b/ntpd/refclock_parse.c @@ -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 * @@ -180,8 +180,9 @@ #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 *