summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorKenneth Soerensen <kenneth.sorensen@spectralink.com>2013-04-10 16:52:52 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2013-11-12 16:12:32 +0100
commitecc7aee9a0eb4f9fbdf4dc2972e8c6361e531b6a (patch)
tree5a7d61dc209c68dcc2a02fd5556b171878ec34d1 /libc
parent20b69920b299585265eb100d0b67e1097ccb1092 (diff)
Make res_init() thread safe.
res_init() was not atomic, which could give undesired behaviour. Now res_init() is completely locked under one lock and the locking is removed from __res_vinit(). Signed-off-by: Kenneth Soerensen <kenneth.sorensen@spectralink.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/inet/resolv.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index ae0dce520..f334d0586 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -3426,6 +3426,7 @@ static void res_sync_func(void)
*/
}
+/* has to be called under __resolv_lock */
static int
__res_vinit(res_state rp, int preinit)
{
@@ -3434,7 +3435,6 @@ __res_vinit(res_state rp, int preinit)
int m = 0;
#endif
- __UCLIBC_MUTEX_LOCK(__resolv_lock);
__close_nameservers();
__open_nameservers();
@@ -3526,7 +3526,6 @@ __res_vinit(res_state rp, int preinit)
rp->options |= RES_INIT;
- __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
return 0;
}
@@ -3576,11 +3575,11 @@ res_init(void)
if (!_res.id)
_res.id = res_randomid();
- __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
-
__res_vinit(&_res, 1);
__res_sync = res_sync_func;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+
return 0;
}
libc_hidden_def(res_init)
@@ -3679,7 +3678,11 @@ struct __res_state *__resp = &_res;
int
res_ninit(res_state statp)
{
- return __res_vinit(statp, 0);
+ int ret;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ ret = __res_vinit(statp, 0);
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ return ret;
}
#endif /* L_res_init */