1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
Index: plugins/check_ntp_time.c
===================================================================
--- plugins/check_ntp_time.c (revision 1884)
+++ plugins/check_ntp_time.c (working copy)
@@ -249,8 +249,12 @@
int best_offset_server(const ntp_server_results *slist, int nservers){
int i=0, j=0, cserver=0, candidates[5], csize=0;
+ if (verbose>2)
+ printf("best_offset_server() line %d: nservers=%d\n", __LINE__, nservers);
/* for each server */
for(cserver=0; cserver<nservers; cserver++){
+ if (verbose>2)
+ printf("best_offset_server() line %d: cserver=%d\n", __LINE__, cserver);
/* sort out servers with error flags */
if ( LI(slist[cserver].flags) != LI_NOWARNING ){
if (verbose) printf("discarding peer id %d: flags=%d\n", cserver, LI(slist[cserver].flags));
@@ -261,25 +265,37 @@
for(i=0; i<csize; i++){
/* does it have an equal or better stratum? */
if(slist[cserver].stratum <= slist[i].stratum){
+ if (verbose>2)
+ printf("best_offset_server() line %d: slist[%d].stratum <= slist[%d].stratum\n", __LINE__, cserver, i);
/* does it have an equal or better dispersion? */
if(slist[cserver].rtdisp <= slist[i].rtdisp){
+ if (verbose>2)
+ printf("best_offset_server() line %d: slist[%d].rtdisp <= slist[%d].rtdisp\n", __LINE__, cserver, i);
/* does it have a better rtdelay? */
if(slist[cserver].rtdelay < slist[i].rtdelay){
+ if (verbose>2)
+ printf("best_offset_server() line %d: slist[%d].rtdelay < slist[%d].rtdelay\n", __LINE__, cserver, i);
break;
}
}
}
+ if (verbose>2)
+ printf("best_offset_server() line %d: i=%d, csize=%d\n", __LINE__, i, csize);
}
/* if we haven't reached the current list's end, move everyone
* over one to the right, and insert the new candidate */
if(i<csize){
for(j=5; j>i; j--){
+ if (verbose>2)
+ printf("best_offset_server() line %d: candidates[%d]=candidates[%d-1] (i=%d, csize=%d)\n", __LINE__, j, j, i, csize);
candidates[j]=candidates[j-1];
}
}
/* regardless, if they should be on the list... */
if(i<5) {
+ if (verbose>2)
+ printf("best_offset_server() line %d: candidates[%d]=%d (csize=%d)\n", __LINE__, i, cserver, csize);
candidates[i]=cserver;
if(csize<5) csize++;
/* otherwise discard the server */
@@ -337,6 +353,7 @@
servers=(ntp_server_results*)malloc(sizeof(ntp_server_results)*num_hosts);
if(servers==NULL) die(STATE_UNKNOWN, "can not allocate server array");
memset(servers, 0, sizeof(ntp_server_results)*num_hosts);
+ DBG(printf("Found %d peers to check\n", num_hosts));
/* setup each socket for writing, and the corresponding struct pollfd */
ai_tmp=ai;
|