06278898f9b5d197962cfde0c1788a5f18279752
[openwrt/openwrt.git] / toolchain / uClibc / patches-0.9.33.2 / 136-inet_make_res_init_thread_safe.patch
1 --- a/libc/inet/resolv.c
2 +++ b/libc/inet/resolv.c
3 @@ -3432,6 +3432,7 @@ static void res_sync_func(void)
4 */
5 }
6
7 +/* has to be called under __resolv_lock */
8 static int
9 __res_vinit(res_state rp, int preinit)
10 {
11 @@ -3440,7 +3441,6 @@ __res_vinit(res_state rp, int preinit)
12 int m = 0;
13 #endif
14
15 - __UCLIBC_MUTEX_LOCK(__resolv_lock);
16 __close_nameservers();
17 __open_nameservers();
18
19 @@ -3532,7 +3532,6 @@ __res_vinit(res_state rp, int preinit)
20
21 rp->options |= RES_INIT;
22
23 - __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
24 return 0;
25 }
26
27 @@ -3582,11 +3581,11 @@ res_init(void)
28 if (!_res.id)
29 _res.id = res_randomid();
30
31 - __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
32 -
33 __res_vinit(&_res, 1);
34 __res_sync = res_sync_func;
35
36 + __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
37 +
38 return 0;
39 }
40 libc_hidden_def(res_init)
41 @@ -3687,7 +3686,11 @@ struct __res_state *__resp = &_res;
42 int
43 res_ninit(res_state statp)
44 {
45 - return __res_vinit(statp, 0);
46 + int ret;
47 + __UCLIBC_MUTEX_LOCK(__resolv_lock);
48 + ret = __res_vinit(statp, 0);
49 + __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
50 + return ret;
51 }
52
53 #endif /* L_res_init */