diff options
Diffstat (limited to 'nss')
-rw-r--r-- | nss/getXXbyYY_r.c | 26 | ||||
-rw-r--r-- | nss/nsswitch.c | 12 |
2 files changed, 30 insertions, 8 deletions
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index a4dc0011a2..8a38b0d628 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -88,6 +88,12 @@ extern struct __res_state _res; /* The lookup function for the first entry of this service. */ extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp); +/* Nonzero if the NSCD is not available. This variable will be increased + whenever we try to use the NSCD but see it is not avilable. So we + can recheck the presence every once in a while. */ +extern int __nss_nscd_not_available; +/* Interval in which we transfer retry to contact the NSCD. */ +#define NSS_NSCD_RETRY 100 int @@ -111,11 +117,21 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, #endif #ifdef USE_NSCD - nscd_status = NSCD_NAME (ADD_VARIABLES, resbuf, buffer, buflen H_ERRNO_VAR); - if (nscd_status < 1) + if (__nss_nscd_not_available && ++__nss_nscd_not_available > NSS_NSCD_RETRY) + __nss_nscd_not_available = 0; + + if (!__nss_nscd_not_available) { - *result = nscd_status == 0 ? resbuf : NULL; - return nscd_status; + nscd_status = NSCD_NAME (ADD_VARIABLES, resbuf, buffer, buflen + H_ERRNO_VAR); + if (nscd_status < 1) + { + *result = nscd_status == 0 ? resbuf : NULL; + return nscd_status; + } + if (nscd_status == 2) + /* This return value indicates that contacting the server failed. */ + __nss_nscd_not_available = 1; } #endif @@ -152,7 +168,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, status = (*fct) (ADD_VARIABLES, resbuf, buffer, buflen, __errno_location () H_ERRNO_VAR); - /* The the status is NSS_STATUS_TRYAGAIN and errno is ERANGE the + /* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the provided buffer is too small. In this case we should give the user the possibility to enlarge the buffer and we should not simply go on with the next service (even if the TRYAGAIN diff --git a/nss/nsswitch.c b/nss/nsswitch.c index 65da26b185..2a3e44a37d 100644 --- a/nss/nsswitch.c +++ b/nss/nsswitch.c @@ -69,6 +69,9 @@ static struct __libc_lock_define_initialized (static, lock) +/* Nonzero if no NSCD is available. */ +int __nss_nscd_not_available; + #if !defined DO_STATIC_NSS || defined PIC /* String with revision number of the shared object files. */ static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15; @@ -380,7 +383,7 @@ nss_lookup_function (service_user *ni, const char *fct_name) /* Load the shared library. */ size_t shlen = (7 + strlen (ni->library->name) + 3 + strlen (__nss_shlib_revision) + 1); - + int saved_errno = errno; struct do_open_args args; args.shlib_name = __alloca (shlen); args.ni = ni; @@ -393,8 +396,11 @@ nss_lookup_function (service_user *ni, const char *fct_name) __nss_shlib_revision); if (nss_dlerror_run (do_open, &args) != 0) - /* Failed to load the library. */ - ni->library->lib_handle = (void *) -1l; + { + /* Failed to load the library. */ + ni->library->lib_handle = (void *) -1l; + __set_errno (saved_errno); + } } if (ni->library->lib_handle == (void *) -1l) |