Changeset 3476154bc836934aa71aaecb12a5a2443a6fc26d
- Timestamp:
- 08/09/12 16:34:25 (10 months ago)
- git-parent:
[a36e20f834b280d8a64b7271e670e7ccf3b39e90], [666f9c351646125cb4a68c692457e6fdf7432534]
- Files:
-
- src/noit_check.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/noit_check.c
r1eb8351 r666f9c3 114 114 return 0; 115 115 } 116 static int 117 noit_check_add_to_list(noit_check_t *new_check) { 118 if(!(new_check->flags & NP_TRANSIENT)) { 119 /* This remove could fail -- no big deal */ 120 noit_skiplist_remove(&polls_by_name, new_check, NULL); 121 122 /* This insert could fail.. which means we have a conflict on 123 * target`name. That should result in the check being disabled. */ 124 if(!noit_skiplist_insert(&polls_by_name, new_check)) { 125 noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n", 126 new_check->target, new_check->name); 127 new_check->flags |= NP_DISABLED; 128 } 129 } 130 return 1; 131 } 116 132 117 133 u_int64_t noit_check_completion_count() { … … 191 207 if(ac->period < bc->period) return -1; 192 208 if(ac->period == bc->period) return 0; 209 return 1; 210 } 211 static int __check_target_ip_compare(const void *a, const void *b) { 212 const noit_check_t *ac = a; 213 const noit_check_t *bc = b; 214 int rv; 215 if (ac->target_ip == NULL) return 1; 216 if (bc->target_ip == NULL) return -1; 217 if((rv = strcmp(ac->target_ip, bc->target_ip)) != 0) return rv; 218 if (ac->name == NULL) return 1; 219 if (bc->name == NULL) return -1; 220 if((rv = strcmp(ac->name, bc->name)) != 0) return rv; 193 221 return 1; 194 222 } … … 525 553 noit_skiplist_set_compare(&polls_by_name, __check_name_compare, 526 554 __check_name_compare); 555 noit_skiplist_add_index(&polls_by_name, __check_target_ip_compare, 556 __check_target_ip_compare); 527 557 noit_skiplist_init(&watchlist); 528 558 noit_skiplist_set_compare(&watchlist, __watchlist_compare, … … 710 740 int8_t family; 711 741 int rv, failed = 0; 742 char old_target_ip[INET6_ADDRSTRLEN]; 712 743 union { 713 744 struct in_addr addr4; 714 745 struct in6_addr addr6; 715 746 } a; 747 748 memset(old_target_ip, 0, INET6_ADDRSTRLEN); 749 strlcpy(old_target_ip, new_check->target_ip, sizeof(old_target_ip)); 716 750 717 751 family = NOIT_CHECK_PREFER_V6(new_check) ? AF_INET6 : AF_INET; … … 741 775 noitL(noit_error, "inet_ntop failed [%s] -> %d\n", ip_str, errno); 742 776 } 777 if ((failed == 0) && (new_check->name != NULL) && (strcmp(old_target_ip, new_check->target_ip) != 0)) { 778 noit_check_add_to_list(new_check); 779 } 743 780 return failed; 744 781 } … … 834 871 new_check->flags = (new_check->flags & ~mask) | flags; 835 872 836 if(!(new_check->flags & NP_TRANSIENT)) { 837 /* This remove could fail -- no big deal */ 838 noit_skiplist_remove(&polls_by_name, new_check, NULL); 839 840 /* This insert could fail.. which means we have a conflict on 841 * target`name. That should result in the check being disabled. */ 842 if(!noit_skiplist_insert(&polls_by_name, new_check)) { 843 noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n", 844 new_check->target, new_check->name); 845 new_check->flags |= NP_DISABLED; 846 } 847 } 873 noit_check_add_to_list(new_check); 848 874 noit_check_log_check(new_check); 849 875 return 0; … … 1013 1039 int count = 0; 1014 1040 noit_check_t pivot; 1041 noit_skiplist *tlist; 1015 1042 noit_skiplist_node *next; 1043 noit_skiplist_node *sn; 1044 1045 sn = noit_skiplist_getlist(polls_by_name.index); 1046 tlist = sn->data; 1016 1047 1017 1048 memset(&pivot, 0, sizeof(pivot)); 1018 pivot.target = (char *)target;1049 strlcpy(pivot.target_ip, (char*)target, sizeof(pivot.target_ip)); 1019 1050 pivot.name = ""; 1020 noit_skiplist_find_neighbors(&polls_by_name, &pivot, NULL, NULL, &next); 1051 pivot.target = ""; 1052 noit_skiplist_find_neighbors(tlist, &pivot, NULL, NULL, &next); 1021 1053 while(next && next->data) { 1022 1054 noit_check_t *check = next->data; 1023 if(strcmp(check->target , target)) break;1055 if(strcmp(check->target_ip, target)) break; 1024 1056 count += f(check,closure); 1025 1057 noit_skiplist_next(&polls_by_name, &next);
