netresolv: ensure pthread_rwlock is initialized before use

Under some circumstances the pthread_rwlock protecting the name service
configuration was not initialized, and the calls to rdlock/wrlock would
silently fail.
This commit is contained in:
Hamish Morrison 2015-06-28 23:17:19 +01:00
parent 67c816c41c
commit 227af8c052

View File

@ -158,7 +158,8 @@ static pthread_once_t _nslockinit = PTHREAD_ONCE_INIT;
static void lockinit()
{
pthread_rwlock_init(&_nslock, NULL);
int result = pthread_rwlock_init(&_nslock, NULL);
assert(result == 0);
}
/*
@ -509,8 +510,6 @@ _nsconfigure(void)
return (0);
}
pthread_once(&_nslockinit, lockinit);
/*
* Ok, we've decided we need to update the nsswitch configuration
* structures. Acquire a write-lock on _nslock while continuing
@ -614,6 +613,8 @@ nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database,
if (database == NULL || method == NULL || defaults == NULL)
return (NS_UNAVAIL);
pthread_once(&_nslockinit, lockinit);
/*
* In both the threaded and non-threaded cases, avoid reloading
* the configuration if the current thread is already running