136-inet_make_res_init_thread_safe.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. +/* has to be called under __resolv_lock */
  7. static int
  8. __res_vinit(res_state rp, int preinit)
  9. {
  10. @@ -3440,7 +3441,6 @@ __res_vinit(res_state rp, int preinit)
  11. int m = 0;
  12. #endif
  13. - __UCLIBC_MUTEX_LOCK(__resolv_lock);
  14. __close_nameservers();
  15. __open_nameservers();
  16. @@ -3532,7 +3532,6 @@ __res_vinit(res_state rp, int preinit)
  17. rp->options |= RES_INIT;
  18. - __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
  19. return 0;
  20. }
  21. @@ -3582,11 +3581,11 @@ res_init(void)
  22. if (!_res.id)
  23. _res.id = res_randomid();
  24. - __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
  25. -
  26. __res_vinit(&_res, 1);
  27. __res_sync = res_sync_func;
  28. + __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
  29. +
  30. return 0;
  31. }
  32. libc_hidden_def(res_init)
  33. @@ -3687,7 +3686,11 @@ struct __res_state *__resp = &_res;
  34. int
  35. res_ninit(res_state statp)
  36. {
  37. - return __res_vinit(statp, 0);
  38. + int ret;
  39. + __UCLIBC_MUTEX_LOCK(__resolv_lock);
  40. + ret = __res_vinit(statp, 0);
  41. + __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
  42. + return ret;
  43. }
  44. #endif /* L_res_init */