ntp_intres.c (289764) | ntp_intres.c (298695) |
---|---|
1/* 2 * ntp_intres.c - Implements a generic blocking worker child or thread, 3 * initially to provide a nonblocking solution for DNS 4 * name to address lookups available with getaddrinfo(). 5 * 6 * This is a new implementation as of 2009 sharing the filename and 7 * very little else with the prior implementation, which used a 8 * temporary file to receive a single set of requests from the parent, --- 187 unchanged lines hidden (view full) --- 196#ifdef HAVE_RES_INIT 197static time_t next_res_init; 198#endif 199 200 201/* === forward declarations === */ 202static u_int reserve_dnschild_ctx(void); 203static u_int get_dnschild_ctx(void); | 1/* 2 * ntp_intres.c - Implements a generic blocking worker child or thread, 3 * initially to provide a nonblocking solution for DNS 4 * name to address lookups available with getaddrinfo(). 5 * 6 * This is a new implementation as of 2009 sharing the filename and 7 * very little else with the prior implementation, which used a 8 * temporary file to receive a single set of requests from the parent, --- 187 unchanged lines hidden (view full) --- 196#ifdef HAVE_RES_INIT 197static time_t next_res_init; 198#endif 199 200 201/* === forward declarations === */ 202static u_int reserve_dnschild_ctx(void); 203static u_int get_dnschild_ctx(void); |
204static void alloc_dnsworker_context(u_int); 205/* static void free_dnsworker_context(u_int); */ | |
206static dnsworker_ctx * get_worker_context(blocking_child *, u_int); 207static void scheduled_sleep(time_t, time_t, 208 dnsworker_ctx *); 209static void manage_dns_retry_interval(time_t *, time_t *, 210 int *, 211 time_t *); 212static int should_retry_dns(int, int); 213#ifdef HAVE_RES_INIT --- 730 unchanged lines hidden (view full) --- 944 945 if (UINT_MAX == shared_ctx) 946 shared_ctx = reserve_dnschild_ctx(); 947 948 return shared_ctx; 949} 950 951 | 204static dnsworker_ctx * get_worker_context(blocking_child *, u_int); 205static void scheduled_sleep(time_t, time_t, 206 dnsworker_ctx *); 207static void manage_dns_retry_interval(time_t *, time_t *, 208 int *, 209 time_t *); 210static int should_retry_dns(int, int); 211#ifdef HAVE_RES_INIT --- 730 unchanged lines hidden (view full) --- 942 943 if (UINT_MAX == shared_ctx) 944 shared_ctx = reserve_dnschild_ctx(); 945 946 return shared_ctx; 947} 948 949 |
952static void 953alloc_dnsworker_context( 954 u_int idx 955 ) 956{ 957 const size_t worker_context_sz = sizeof(*dnsworker_contexts[0]); 958 959 REQUIRE(NULL == dnsworker_contexts[idx]); 960 dnsworker_contexts[idx] = emalloc_zero(worker_context_sz); 961} 962 963 | |
964static dnsworker_ctx * 965get_worker_context( 966 blocking_child * c, 967 u_int idx 968 ) 969{ | 950static dnsworker_ctx * 951get_worker_context( 952 blocking_child * c, 953 u_int idx 954 ) 955{ |
970 static size_t ps = sizeof(dnsworker_contexts[0]); 971 u_int min_new_alloc; 972 u_int new_alloc; 973 size_t octets; 974 size_t new_octets; | 956 u_int min_new_alloc; 957 u_int new_alloc; 958 size_t octets; 959 size_t new_octets; 960 dnsworker_ctx * retv; |
975 | 961 |
962 worker_global_lock(TRUE); 963 |
|
976 if (dnsworker_contexts_alloc <= idx) { 977 min_new_alloc = 1 + idx; 978 /* round new_alloc up to nearest multiple of 4 */ 979 new_alloc = (min_new_alloc + 4) & ~(4 - 1); | 964 if (dnsworker_contexts_alloc <= idx) { 965 min_new_alloc = 1 + idx; 966 /* round new_alloc up to nearest multiple of 4 */ 967 new_alloc = (min_new_alloc + 4) & ~(4 - 1); |
980 new_octets = new_alloc * ps; 981 octets = dnsworker_contexts_alloc * ps; | 968 new_octets = new_alloc * sizeof(dnsworker_ctx*); 969 octets = dnsworker_contexts_alloc * sizeof(dnsworker_ctx*); |
982 dnsworker_contexts = erealloc_zero(dnsworker_contexts, 983 new_octets, octets); 984 dnsworker_contexts_alloc = new_alloc; | 970 dnsworker_contexts = erealloc_zero(dnsworker_contexts, 971 new_octets, octets); 972 dnsworker_contexts_alloc = new_alloc; |
973 retv = emalloc_zero(sizeof(dnsworker_ctx)); 974 dnsworker_contexts[idx] = retv; 975 } else if (NULL == (retv = dnsworker_contexts[idx])) { 976 retv = emalloc_zero(sizeof(dnsworker_ctx)); 977 dnsworker_contexts[idx] = retv; |
|
985 } | 978 } |
986 987 if (NULL == dnsworker_contexts[idx]) 988 alloc_dnsworker_context(idx); 989 ZERO(*dnsworker_contexts[idx]); 990 dnsworker_contexts[idx]->c = c; 991 992 return dnsworker_contexts[idx]; | 979 980 worker_global_lock(FALSE); 981 982 ZERO(*retv); 983 retv->c = c; 984 return retv; |
993} 994 995 996static void 997scheduled_sleep( 998 time_t scheduled, 999 time_t earliest, 1000 dnsworker_ctx * worker_ctx --- 128 unchanged lines hidden --- | 985} 986 987 988static void 989scheduled_sleep( 990 time_t scheduled, 991 time_t earliest, 992 dnsworker_ctx * worker_ctx --- 128 unchanged lines hidden --- |