From: Harlan Stenn Date: Sun, 29 Mar 2015 01:49:10 +0000 (+0000) Subject: [Bug 2346] "graceful termination" signals do not do peer cleanup X-Git-Tag: NTP_4_2_8P2_RC1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e92a6bdba360267a6afea4d9963da420098bf379;p=thirdparty%2Fntp.git [Bug 2346] "graceful termination" signals do not do peer cleanup bk: 55175a16W3_Wss1Z2sowk4vnvGC8ng --- diff --git a/ChangeLog b/ChangeLog index aea1108a6..bbc77380c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * [Bug 1787] DCF77's formerly "antenna" bit is "call bit" since 2003. * [Bug 1960] setsockopt IPV6_MULTICAST_IF: Invalid argument. +* [Bug 2346] "graceful termination" signals do not do peer cleanup. * [Bug 2728] See if C99-style structure initialization works. * [Bug 2747] Upgrade libevent to 2.1.5-beta. * [Bug 2749] ntp/lib/NTP/Util.pm needs update for ntpq -w, IPv6, .POOL. . diff --git a/include/ntpd.h b/include/ntpd.h index 9f07e4ef7..8ccd5d2e0 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -188,6 +188,7 @@ extern void unpeer (struct peer *); extern void clear_all (void); extern int score_all (struct peer *); extern struct peer *findmanycastpeer(struct recvbuf *); +extern void peer_cleanup (void); /* ntp_crypto.c */ #ifdef AUTOKEY diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index 495ee30af..d42d804d4 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -92,6 +92,7 @@ int peer_free_count; /* count of free structures */ * value every time an association is mobilized. */ static associd_t current_association_ID; /* association ID */ +static associd_t initial_association_ID; /* association ID */ /* * Memory allocation watermarks. @@ -147,6 +148,7 @@ init_peer(void) do current_association_ID = ntp_random() & ASSOCID_MAX; while (!current_association_ID); + initial_association_ID = current_association_ID; } @@ -1036,3 +1038,21 @@ findmanycastpeer( return peer; } + +/* peer_cleanup - clean peer list prior to shutdown */ +void peer_cleanup(void) +{ + struct peer *peer; + associd_t assoc; + + for (assoc = initial_association_ID; assoc != current_association_ID; assoc++) { + if (assoc != 0U) { + peer = findpeerbyassoc(assoc); + if (peer != NULL) + unpeer(peer); + } + } + peer = findpeerbyassoc(current_association_ID); + if (peer != NULL) + unpeer(peer); +} diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index c017ef34d..529e6ce1b 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -1262,6 +1262,7 @@ finish( if (mdns != NULL) DNSServiceRefDeallocate(mdns); # endif + peer_cleanup(); exit(0); } #endif /* !SIM && SIGDIE1 */