From: Harlan Stenn Date: Tue, 12 Oct 2010 04:06:48 +0000 (-0400) Subject: Lose peer_count from ntp_peer.c and ntp_proto.c (Dave Mills) X-Git-Tag: NTP_4_2_7P62~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f2c51462c6bd442a60e7cbb7089b7c52a84f340;p=thirdparty%2Fntp.git Lose peer_count from ntp_peer.c and ntp_proto.c (Dave Mills) bk: 4cb3ded86qsAjsKy_6289NAEUqzBDA --- diff --git a/ChangeLog b/ChangeLog index fe4d0de84..5dacfc080 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ * [Bug 1660] from 4.2.6p3-RC3: On some systems, test is in /usr/bin, not /bin. * [Bug 1661] from 4.2.6p3-RC3: Re-indent refclock_ripencc.c. +* Lose peer_count from ntp_peer.c and ntp_proto.c (Dave Mills). (4.2.7p61) 2010/10/06 Released by Harlan Stenn * Documentation and code cleanup from Dave Mills. No more NTP_MAXASSOC. (4.2.7p60) 2010/10/04 Released by Harlan Stenn diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index f496a5fdd..a95c2326c 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -85,7 +85,6 @@ struct peer *assoc_hash[NTP_HASH_SIZE]; /* association ID hash table */ int assoc_hash_count[NTP_HASH_SIZE];/* peers in each bucket */ struct peer *peer_list; /* peer structures list */ static struct peer *peer_free; /* peer structures free list */ -int peer_count; /* count of peer_list */ int peer_free_count; /* count of free structures */ /* @@ -411,8 +410,7 @@ score( /* * free_peer - internal routine to free memory referred to by a struct * peer and return it to the peer free list. If unlink is - * nonzero, unlink from the various lists and decrement - * peer_count. + * nonzero, unlink from the various lists. */ static void free_peer( @@ -456,8 +454,6 @@ free_peer( if (NULL == unlinked) msyslog(LOG_ERR, "%s not in peer list!", stoa(&p->srcadr)); - else - peer_count--; } if (p->hostname != NULL) @@ -943,13 +939,10 @@ newpeer( LINK_SLIST(assoc_hash[hash], peer, aid_link); assoc_hash_count[hash]++; LINK_SLIST(peer_list, peer, p_link); - peer_count++; restrict_source(&peer->srcadr, 0, 0); - snprintf(tbuf, sizeof(tbuf), "assoc %d", peer->associd); report_event(PEVNT_MOBIL, peer, tbuf); - DPRINTF(1, ("newpeer: %s->%s mode %u vers %u poll %u %u flags 0x%x 0x%x ttl %u key %08x\n", latoa(peer->dstadr), stoa(&peer->srcadr), peer->hmode, peer->version, peer->minpoll, peer->maxpoll, peer->flags, diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 97b4109f5..493f1f12b 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -2309,11 +2309,14 @@ clock_select(void) * Allocate dynamic space depending on the number of * associations. */ - endpoint_size = peer_count * 3 * sizeof(struct endpoint); - indx_size = peer_count * 3 * sizeof(int); - peers_size = peer_count * sizeof(struct peer *); - synch_size = peer_count * sizeof(double); - error_size = peer_count * sizeof(double); + nlist = 0; + for (peer = peer_list; peer != NULL; peer = peer->p_link) + nlist++; + endpoint_size = nlist * 2 * sizeof(struct endpoint); + indx_size = nlist * 2 * sizeof(int); + peers_size = nlist * sizeof(struct peer *); + synch_size = nlist * sizeof(double); + error_size = nlist * sizeof(double); octets = endpoint_size + indx_size + peers_size + synch_size + error_size; endpoint = erealloc(endpoint, octets); @@ -2395,7 +2398,9 @@ clock_select(void) e = peer->offset; /* upper end */ f = root_distance(peer); e = e + f; + j = 0; for (i = nl3 - 1; i >= 0; i--) { + j = nl3 - 1 + 2; if (e >= endpoint[indx[i]].val) break;