From 227af8c052dcdc287a785cb5a008a5a6d37b8c72 Mon Sep 17 00:00:00 2001 From: Hamish Morrison Date: Sun, 28 Jun 2015 23:17:19 +0100 Subject: [PATCH] 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. --- src/kits/network/netresolv/irs/nsdispatch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/kits/network/netresolv/irs/nsdispatch.c b/src/kits/network/netresolv/irs/nsdispatch.c index 5169886a7f..c84d4c950d 100644 --- a/src/kits/network/netresolv/irs/nsdispatch.c +++ b/src/kits/network/netresolv/irs/nsdispatch.c @@ -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