Pārlūkot izejas kodu

check_ntp_time calls `write` on a UDP socket without a successful call to `connect`

Fix for issue #171
John C. Frickson 8 gadi atpakaļ
vecāks
revīzija
b1509b77db
2 mainītis faili ar 5 papildinājumiem un 0 dzēšanām
  1. 1 0
      NEWS
  2. 4 0
      plugins/check_ntp_time.c

+ 1 - 0
NEWS

@@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases.
 	FIXES
 	FIXES
 	check_disk: autofs being mounted despite '-l'. Fixed, and also excluded some system "fake" mountpoints
 	check_disk: autofs being mounted despite '-l'. Fixed, and also excluded some system "fake" mountpoints
 	check_ntp_time: Periodically returns "Socket timeout" when one of several ntp server doesn't respond
 	check_ntp_time: Periodically returns "Socket timeout" when one of several ntp server doesn't respond
+	check_ntp_time calls `write` on a UDP socket without a successful call to `connect`
 
 
 
 
 2.2.1 2017-04-19
 2.2.1 2017-04-19

+ 4 - 0
plugins/check_ntp_time.c

@@ -80,6 +80,7 @@ typedef struct {
 /* this structure holds data about results from querying offset from a peer */
 /* this structure holds data about results from querying offset from a peer */
 typedef struct {
 typedef struct {
 	time_t waiting;         /* ts set when we started waiting for a response */
 	time_t waiting;         /* ts set when we started waiting for a response */
+	int connected;          /* don't try to "write()" if "connect()" fails */
 	int num_responses;      /* number of successfully recieved responses */
 	int num_responses;      /* number of successfully recieved responses */
 	uint8_t stratum;        /* copied verbatim from the ntp_message */
 	uint8_t stratum;        /* copied verbatim from the ntp_message */
 	double rtdelay;         /* converted from the ntp_message */
 	double rtdelay;         /* converted from the ntp_message */
@@ -355,6 +356,7 @@ double offset_request(const char *host, int *status){
 			ufds[i].fd=socklist[i];
 			ufds[i].fd=socklist[i];
 			ufds[i].events=POLLIN;
 			ufds[i].events=POLLIN;
 			ufds[i].revents=0;
 			ufds[i].revents=0;
+			servers[i].connected=1;
 		}
 		}
 		ai_tmp = ai_tmp->ai_next;
 		ai_tmp = ai_tmp->ai_next;
 	}
 	}
@@ -370,6 +372,8 @@ double offset_request(const char *host, int *status){
 		now_time=time(NULL);
 		now_time=time(NULL);
 
 
 		for(i=0; i<num_hosts; i++){
 		for(i=0; i<num_hosts; i++){
+			if(servers[i].connected == 0)
+				continue;
 			if(servers[i].waiting<now_time && servers[i].num_responses<AVG_NUM){
 			if(servers[i].waiting<now_time && servers[i].num_responses<AVG_NUM){
 				if(verbose && servers[i].waiting != 0) printf("re-");
 				if(verbose && servers[i].waiting != 0) printf("re-");
 				if(verbose) printf("sending request to peer %d\n", i);
 				if(verbose) printf("sending request to peer %d\n", i);