Back to index

glibc  2.9
Defines | Typedefs | Functions
getXXbyYY_r.c File Reference
#include <assert.h>
#include <atomic.h>
#include <errno.h>
#include <stdbool.h>
#include "nsswitch.h"
#include "sysdep.h"
#include <shlib-compat.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define REENTRANT_NAME   APPEND_R (FUNCTION_NAME)
#define REENTRANT2_NAME   NULL
#define APPEND_R(name)   APPEND_R1 (name)
#define APPEND_R1(name)   name##_r
#define INTERNAL(name)   INTERNAL1 (name)
#define INTERNAL1(name)   __##name
#define NEW(name)   NEW1 (name)
#define NEW1(name)   __new_##name
#define FUNCTION_NAME_STRING   STRINGIZE (FUNCTION_NAME)
#define REENTRANT_NAME_STRING   STRINGIZE (REENTRANT_NAME)
#define REENTRANT2_NAME_STRING   NULL
#define DATABASE_NAME_STRING   STRINGIZE (DATABASE_NAME)
#define STRINGIZE(name)   STRINGIZE1 (name)
#define STRINGIZE1(name)   #name
#define DB_LOOKUP_FCT   CONCAT3_1 (__nss_, DATABASE_NAME, _lookup2)
#define CONCAT3_1(Pre, Name, Post)   CONCAT3_2 (Pre, Name, Post)
#define CONCAT3_2(Pre, Name, Post)   Pre##Name##Post
#define H_ERRNO_PARM
#define H_ERRNO_VAR
#define H_ERRNO_VAR_P   NULL
#define EXTRA_PARAMS
#define EXTRA_VARIABLES
#define AF_VAL   AF_INET
#define do_default_symbol_version(real, name, version)   versioned_symbol (libc, real, name, version)

Typedefs

typedef enum nss_status(* lookup_function )(ADD_PARAMS, LOOKUP_TYPE *, char *, size_t, int *H_ERRNO_PARM EXTRA_PARAMS)

Functions

int DB_LOOKUP_FCT (service_user **nip, const char *name, const char *name2, void **fctp) internal_function
 libc_hidden_proto (DB_LOOKUP_FCT)
 strong_alias (INTERNAL(REENTRANT_NAME), NEW(REENTRANT_NAME))
 do_default_symbol_version (NEW(REENTRANT_NAME), REENTRANT_NAME, GLIBC_2_1_2)

Define Documentation

#define AF_VAL   AF_INET

Definition at line 130 of file getXXbyYY_r.c.

#define APPEND_R (   name)    APPEND_R1 (name)

Definition at line 76 of file getXXbyYY_r.c.

#define APPEND_R1 (   name)    name##_r

Definition at line 77 of file getXXbyYY_r.c.

#define CONCAT3_1 (   Pre,
  Name,
  Post 
)    CONCAT3_2 (Pre, Name, Post)

Definition at line 105 of file getXXbyYY_r.c.

#define CONCAT3_2 (   Pre,
  Name,
  Post 
)    Pre##Name##Post

Definition at line 106 of file getXXbyYY_r.c.

Definition at line 99 of file getXXbyYY_r.c.

#define DB_LOOKUP_FCT   CONCAT3_1 (__nss_, DATABASE_NAME, _lookup2)

Definition at line 104 of file getXXbyYY_r.c.

#define do_default_symbol_version (   real,
  name,
  version 
)    versioned_symbol (libc, real, name, version)

Definition at line 334 of file getXXbyYY_r.c.

#define EXTRA_PARAMS

Definition at line 121 of file getXXbyYY_r.c.

#define EXTRA_VARIABLES

Definition at line 124 of file getXXbyYY_r.c.

Definition at line 92 of file getXXbyYY_r.c.

#define H_ERRNO_PARM

Definition at line 115 of file getXXbyYY_r.c.

#define H_ERRNO_VAR

Definition at line 116 of file getXXbyYY_r.c.

#define H_ERRNO_VAR_P   NULL

Definition at line 117 of file getXXbyYY_r.c.

#define INTERNAL (   name)    INTERNAL1 (name)

Definition at line 78 of file getXXbyYY_r.c.

#define INTERNAL1 (   name)    __##name

Definition at line 79 of file getXXbyYY_r.c.

#define NEW (   name)    NEW1 (name)

Definition at line 80 of file getXXbyYY_r.c.

#define NEW1 (   name)    __new_##name

Definition at line 81 of file getXXbyYY_r.c.

#define REENTRANT2_NAME   NULL

Definition at line 74 of file getXXbyYY_r.c.

Definition at line 97 of file getXXbyYY_r.c.

Definition at line 70 of file getXXbyYY_r.c.

Definition at line 93 of file getXXbyYY_r.c.

#define STRINGIZE (   name)    STRINGIZE1 (name)

Definition at line 100 of file getXXbyYY_r.c.

#define STRINGIZE1 (   name)    #name

Definition at line 101 of file getXXbyYY_r.c.


Typedef Documentation

Definition at line 134 of file getXXbyYY_r.c.


Function Documentation

int DB_LOOKUP_FCT ( service_user **  nip,
const char *  name,
const char *  name2,
void **  fctp 
)

Definition at line 142 of file getXXbyYY_r.c.

{
  static bool startp_initialized;
  static service_user *startp;
  static lookup_function start_fct;
  service_user *nip;
  union
  {
    lookup_function l;
    void *ptr;
  } fct;

  int no_more;
  enum nss_status status = NSS_STATUS_UNAVAIL;
#ifdef USE_NSCD
  int nscd_status;
#endif
#ifdef NEED_H_ERRNO
  bool any_service = false;
#endif

#ifdef PREPROCESS
  PREPROCESS;
#endif

#ifdef HANDLE_DIGITS_DOTS
  switch (__nss_hostname_digits_dots (name, resbuf, &buffer, NULL,
                                  buflen, result, &status, AF_VAL,
                                  H_ERRNO_VAR_P))
    {
    case -1:
      return errno;
    case 1:
      goto done;
    }
#endif

#ifdef USE_NSCD
  if (NOT_USENSCD_NAME > 0 && ++NOT_USENSCD_NAME > NSS_NSCD_RETRY)
    NOT_USENSCD_NAME = 0;

  if (!NOT_USENSCD_NAME)
    {
      nscd_status = NSCD_NAME (ADD_VARIABLES, resbuf, buffer, buflen, result
                            H_ERRNO_VAR);
      if (nscd_status >= 0)
       return nscd_status;
    }
#endif

  if (! startp_initialized)
    {
      no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING,
                            REENTRANT2_NAME_STRING, &fct.ptr);
      if (no_more)
       {
         void *tmp_ptr = (service_user *) -1l;
         PTR_MANGLE (tmp_ptr);
         startp = tmp_ptr;
       }
      else
       {
#ifdef NEED__RES
         /* The resolver code will really be used so we have to
            initialize it.  */
         if (__res_maybe_init (&_res, 0) == -1)
           {
             *h_errnop = NETDB_INTERNAL;
             *result = NULL;
             return errno;
           }
#endif /* need _res */
#ifdef NEED__RES_HCONF
         if (!_res_hconf.initialized)
           _res_hconf_init ();
#endif /* need _res_hconf */

         void *tmp_ptr = fct.l;
         PTR_MANGLE (tmp_ptr);
         start_fct = tmp_ptr;
         tmp_ptr = nip;
         PTR_MANGLE (tmp_ptr);
         startp = tmp_ptr;
       }

      /* Make sure start_fct and startp are written before
        startp_initialized.  */
      atomic_write_barrier ();
      startp_initialized = true;
    }
  else
    {
      fct.l = start_fct;
      PTR_DEMANGLE (fct.l);
      nip = startp;
      PTR_DEMANGLE (nip);
      no_more = nip == (service_user *) -1l;
    }

  while (no_more == 0)
    {
#ifdef NEED_H_ERRNO
      any_service = true;
#endif

      status = DL_CALL_FCT (fct.l, (ADD_VARIABLES, resbuf, buffer, buflen,
                                &errno H_ERRNO_VAR EXTRA_VARIABLES));

      /* 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
        action tells us so).  */
      if (status == NSS_STATUS_TRYAGAIN
#ifdef NEED_H_ERRNO
         && *h_errnop == NETDB_INTERNAL
#endif
         && errno == ERANGE)
       break;

      no_more = __nss_next2 (&nip, REENTRANT_NAME_STRING,
                          REENTRANT2_NAME_STRING, &fct.ptr, status, 0);
    }

#ifdef HANDLE_DIGITS_DOTS
done:
#endif
  *result = status == NSS_STATUS_SUCCESS ? resbuf : NULL;
#ifdef NEED_H_ERRNO
  if (status != NSS_STATUS_SUCCESS && ! any_service)
    /* We were not able to use any service.  */
    *h_errnop = NO_RECOVERY;
#endif
#ifdef POSTPROCESS
  POSTPROCESS;
#endif

  int res;
  if (status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND)
    res = 0;
  /* Don't pass back ERANGE if this is not for a too-small buffer.  */
  else if (errno == ERANGE && status != NSS_STATUS_TRYAGAIN)
    res = EINVAL;
#ifdef NEED_H_ERRNO
  /* These functions only set errno if h_errno is NETDB_INTERNAL.  */
  else if (status == NSS_STATUS_TRYAGAIN && *h_errnop != NETDB_INTERNAL)
    res = EAGAIN;
#endif
  else
    return errno;

  __set_errno (res);
  return res;
}

Here is the call graph for this function: