Lines 1-15
Link Here
|
1 |
Index: src/libspf2/spf_dns_resolv.c |
1 |
Index: src/libspf2/spf_dns_resolv.c |
2 |
diff -u -p src/libspf2/spf_dns_resolv.c.orig src/libspf2/spf_dns_resolv.c |
2 |
diff -u -p src/libspf2/spf_dns_resolv.c.orig src/libspf2/spf_dns_resolv.c |
3 |
--- src/libspf2/spf_dns_resolv.c.orig Sat Feb 19 11:38:12 2005 |
3 |
--- src/libspf2/spf_dns_resolv.c.orig Thu Oct 16 07:02:03 2008 |
4 |
+++ src/libspf2/spf_dns_resolv.c Mon Jul 31 14:02:57 2006 |
4 |
+++ src/libspf2/spf_dns_resolv.c Fri Oct 24 12:19:29 2008 |
5 |
@@ -71,13 +71,18 @@ typedef struct |
5 |
@@ -92,7 +92,11 @@ static pthread_key_t res_state_key; |
6 |
# define SPF_h_errno h_errno |
|
|
7 |
#endif |
8 |
|
9 |
+#if HAVE_DECL_RES_NINIT |
10 |
static pthread_once_t res_state_control = PTHREAD_ONCE_INIT; |
11 |
static pthread_key_t res_state_key; |
12 |
|
13 |
static void |
6 |
static void |
14 |
SPF_dns_resolv_thread_term(void *arg) |
7 |
SPF_dns_resolv_thread_term(void *arg) |
15 |
{ |
8 |
{ |
Lines 21-102
diff -u -p src/libspf2/spf_dns_resolv.c.
Link Here
|
21 |
free(arg); |
14 |
free(arg); |
22 |
} |
15 |
} |
23 |
|
16 |
|
24 |
@@ -86,6 +91,7 @@ SPF_dns_resolv_init_key() |
17 |
@@ -615,7 +619,7 @@ SPF_dns_resolv_new(SPF_dns_server_t *lay |
25 |
{ |
18 |
#if HAVE_DECL_RES_NINIT |
26 |
pthread_key_create(&res_state_key, SPF_dns_resolv_thread_term); |
|
|
27 |
} |
28 |
+#endif |
29 |
|
30 |
|
31 |
#if 0 |
32 |
@@ -130,8 +136,10 @@ SPF_dns_resolv_lookup(SPF_dns_server_t * |
33 |
int rdlen; |
34 |
const u_char *rdata, *rdata_end; |
35 |
|
36 |
+#if HAVE_DECL_RES_NINIT |
37 |
void *res_spec; |
38 |
struct __res_state *res_state; |
39 |
+#endif |
40 |
|
41 |
SPF_ASSERT_NOTNULL(spf_dns_server); |
42 |
|
43 |
@@ -140,10 +148,15 @@ SPF_dns_resolv_lookup(SPF_dns_server_t * |
44 |
SPF_ASSERT_NOTNULL(spfhook); |
45 |
#endif |
46 |
|
47 |
+#if HAVE_DECL_RES_NINIT |
48 |
res_spec = pthread_getspecific(res_state_key); |
49 |
if (res_spec == NULL) { |
50 |
res_state = (struct __res_state *) |
51 |
malloc(sizeof(struct __res_state)); |
52 |
+ if (res_state == NULL) { |
53 |
+ SPF_error("Failed to call malloc()"); |
54 |
+ } |
55 |
+ memset(res_state, 0, sizeof(*res_state)); |
56 |
if (res_ninit(res_state) != 0) { |
57 |
SPF_error("Failed to call res_ninit()"); |
58 |
} |
59 |
@@ -152,6 +165,11 @@ SPF_dns_resolv_lookup(SPF_dns_server_t * |
60 |
else { |
61 |
res_state = (struct __res_state *)res_spec; |
62 |
} |
63 |
+#else |
64 |
+ if ((_res.options & RES_INIT) == 0 && res_init() != 0) { |
65 |
+ SPF_error("Failed to call res_init()"); |
66 |
+ } |
67 |
+#endif |
68 |
|
69 |
/* |
70 |
* try resolving the name |
71 |
@@ -486,7 +504,9 @@ SPF_dns_resolv_new(SPF_dns_server_t *lay |
72 |
SPF_dns_resolv_config_t *spfhook; |
73 |
#endif |
74 |
|
75 |
+#if HAVE_DECL_RES_NINIT |
76 |
pthread_once(&res_state_control, SPF_dns_resolv_init_key); |
19 |
pthread_once(&res_state_control, SPF_dns_resolv_init_key); |
77 |
+#endif |
|
|
78 |
|
79 |
spf_dns_server = malloc(sizeof(SPF_dns_server_t)); |
80 |
if ( spf_dns_server == NULL ) |
81 |
@@ -517,19 +537,19 @@ SPF_dns_resolv_new(SPF_dns_server_t *lay |
82 |
spfhook = SPF_voidp2spfhook( spf_dns_server->hook ); |
83 |
#endif |
84 |
|
85 |
-#if HAVE_DECL_RES_NINIT |
86 |
#if 0 |
87 |
+#if HAVE_DECL_RES_NINIT |
88 |
if ( res_ninit( &spfhook->res_state ) != 0 ) { |
89 |
free(spfhook); |
90 |
free(spf_dns_server); |
91 |
return NULL; |
92 |
} |
93 |
-#endif |
94 |
#else |
20 |
#else |
95 |
if ( res_init() != 0 ) { |
21 |
- if ( res_init() != 0 ) { |
96 |
free( spf_dns_server ); |
22 |
+ if ((_res.options & RES_INIT) == 0 && res_init() != 0) { |
|
|
23 |
perror("res_init"); |
97 |
return NULL; |
24 |
return NULL; |
98 |
} |
25 |
} |
99 |
+#endif |
|
|
100 |
#endif |
101 |
|
102 |
return spf_dns_server; |