Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/net/nsdispatch.c
Show First 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | |||||
* The first time nsdispatch is called (during a process's lifetime, | * The first time nsdispatch is called (during a process's lifetime, | ||||
* or after nsswitch.conf has been updated), nss_configure will | * or after nsswitch.conf has been updated), nss_configure will | ||||
* prepare global data needed by NSS. | * prepare global data needed by NSS. | ||||
*/ | */ | ||||
static int | static int | ||||
nss_configure(void) | nss_configure(void) | ||||
{ | { | ||||
static time_t confmod; | static time_t confmod; | ||||
static int already_initialized = 0; | |||||
struct stat statbuf; | struct stat statbuf; | ||||
int result, isthreaded; | int result, isthreaded; | ||||
const char *path; | const char *path; | ||||
#ifdef NS_CACHING | #ifdef NS_CACHING | ||||
void *handle; | void *handle; | ||||
#endif | #endif | ||||
result = 0; | result = 0; | ||||
isthreaded = __isthreaded; | isthreaded = __isthreaded; | ||||
#if defined(_NSS_DEBUG) && defined(_NSS_SHOOT_FOOT) | #if defined(_NSS_DEBUG) && defined(_NSS_SHOOT_FOOT) | ||||
/* NOTE WELL: THIS IS A SECURITY HOLE. This must only be built | /* NOTE WELL: THIS IS A SECURITY HOLE. This must only be built | ||||
* for debugging purposes and MUST NEVER be used in production. | * for debugging purposes and MUST NEVER be used in production. | ||||
*/ | */ | ||||
path = getenv("NSSWITCH_CONF"); | path = getenv("NSSWITCH_CONF"); | ||||
if (path == NULL) | if (path == NULL) | ||||
#endif | #endif | ||||
path = _PATH_NS_CONF; | path = _PATH_NS_CONF; | ||||
#ifndef NS_REREAD_CONF | |||||
/* | |||||
* Define NS_REREAD_CONF to have nsswitch notice changes | |||||
* to nsswitch.conf(5) during runtime. This involves calling | |||||
* stat(2) every time, which can result in performance hit. | |||||
*/ | |||||
if (already_initialized) | |||||
return (0); | |||||
already_initialized = 1; | |||||
#endif /* NS_REREAD_CONF */ | |||||
if (stat(path, &statbuf) != 0) | if (stat(path, &statbuf) != 0) | ||||
return (0); | return (0); | ||||
if (statbuf.st_mtime <= confmod) | if (statbuf.st_mtime <= confmod) | ||||
return (0); | return (0); | ||||
if (isthreaded) { | if (isthreaded) { | ||||
(void)_pthread_rwlock_unlock(&nss_lock); | (void)_pthread_rwlock_unlock(&nss_lock); | ||||
result = _pthread_rwlock_wrlock(&nss_lock); | result = _pthread_rwlock_wrlock(&nss_lock); | ||||
if (result != 0) | if (result != 0) | ||||
▲ Show 20 Lines • Show All 410 Lines • Show Last 20 Lines |