Back to index

glibc  2.9
Defines | Functions | Variables
res_libc.c File Reference
#include <atomic.h>
#include <limits.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <bits/libc-lock.h>
#include <tls.h>
#include <shlib-compat.h>

Go to the source code of this file.


#define atomicinclock(lock)   __libc_lock_lock (lock)
#define atomicincunlock(lock)   __libc_lock_unlock (lock)
#define atomicinc(var)   ++var


 __libc_lock_define_initialized (static, lock)
int res_init (void)
int __res_maybe_init (res_state resp, int preinit)


unsigned long long int

Define Documentation

#define atomicinc (   var)    ++var

Definition at line 41 of file res_libc.c.

#define atomicinclock (   lock)    __libc_lock_lock (lock)

Definition at line 39 of file res_libc.c.

Definition at line 40 of file res_libc.c.

Function Documentation

__libc_lock_define_initialized ( static  ,

Definition at line 34 of file getnetgrent_r.c.

  /* Remember the first service_entry, it's always the same.  */
  static bool startp_initialized;
  static service_user *startp;
  int no_more;

  if (!startp_initialized)
      /* Executing this more than once at the same time must yield the
        same result every time.  So we need no locking.  */
      no_more = __nss_netgroup_lookup (nipp, "setnetgrent", fctp);
      startp = no_more ? (service_user *) -1 : *nipp;
      PTR_MANGLE (startp);
      atomic_write_barrier ();
      startp_initialized = true;
      service_user *nip = startp;
      PTR_DEMANGLE (nip);
      if (nip == (service_user *) -1)
       /* No services at all.  */
       return 1;

      /* Reset to the beginning of the service list.  */
      *nipp = nip;
      /* Look up the first function.  */
      no_more = __nss_lookup (nipp, "setnetgrent", NULL, fctp);
  return no_more;
int __res_maybe_init ( res_state  resp,
int  preinit 

Definition at line 95 of file res_libc.c.

       if (resp->options & RES_INIT) {
              if (__res_initstamp != resp->_u._ext.initstamp) {
                     if (resp->nscount > 0) {
                            __res_iclose (resp, true);
                            return __res_vinit (resp, 1);
              return 0;
       } else if (preinit) {
              if (!resp->retrans)
                     resp->retrans = RES_TIMEOUT;
              if (!resp->retry)
                     resp->retry = 4;
              resp->options = RES_DEFAULT;
              if (!resp->id)
                     resp->id = res_randomid ();
              return __res_vinit (resp, 1);
       } else
              return __res_ninit (resp);

Here is the call graph for this function:

int res_init ( void  )

Definition at line 45 of file res_libc.c.

       extern int __res_vinit(res_state, int);

        * These three fields used to be statically initialized.  This made
        * it hard to use this code in a shared library.  It is necessary,
        * now that we're doing dynamic initialization here, that we preserve
        * the old semantics: if an application modifies one of these three
        * fields of _res before res_init() is called, res_init() will not
        * alter them.  Of course, if an application is setting them to
        * _zero_ before calling res_init(), hoping to override what used
        * to be the static default, we can't detect it and unexpected results
        * will follow.  Zero for any of these fields would make no sense,
        * so one can safely assume that the applications were already getting
        * unexpected results.
        * _res.options is tricky since some apps were known to diddle the bits
        * before res_init() was first called. We can't replicate that semantic
        * with dynamic initialization (they may have turned bits off that are
        * set in RES_DEFAULT).  Our solution is to declare such applications
        * "broken".  They could fool us by setting RES_INIT but none do (yet).
       if (!_res.retrans)
              _res.retrans = RES_TIMEOUT;
       if (!_res.retry)
              _res.retry = 4;
       if (!(_res.options & RES_INIT))
              _res.options = RES_DEFAULT;
       else if (_res.nscount > 0)
              __res_iclose (&_res, true); /* Close any VC sockets.  */

        * This one used to initialize implicitly to zero, so unless the app
        * has set it to something in particular, we can randomize it now.
       if (!
     = res_randomid();

       atomicinclock (lock);
       /* Request all threads to re-initialize their resolver states,
          resolv.conf might have changed.  */
       atomicinc (__res_initstamp);
       atomicincunlock (lock);

       return (__res_vinit(&_res, 1));

Here is the call graph for this function:

Variable Documentation

unsigned long long int __res_initstamp attribute_hidden

Definition at line 25 of file init-first.c.