/* Initialize resp if RES_INIT is not yet set or if res_init in some other thread requested re-initializing. */ int __res_maybe_init (res_state resp, int preinit) { if (resp->options & RES_INIT) { if (__res_initstamp != resp->_u._ext.initstamp) { if (resp->nscount > 0) { __res_nclose (resp); int ns; for (ns = 0; ns < MAXNS; ns++) { free (resp->_u._ext.nsaddrs[ns]); resp->_u._ext.nsaddrs[ns] = NULL; } 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); }
/* Initialize resp if RES_INIT is not yet set or if res_init in some other thread requested re-initializing. */ int __res_maybe_init (res_state resp, int preinit) { static time_t last_mtime; struct stat statbuf; int ret; if (resp->options & RES_INIT) { ret = stat (_PATH_RESCONF, &statbuf); __libc_lock_lock (lock); if ((ret == 0) && (last_mtime != statbuf.st_mtime)) { last_mtime = statbuf.st_mtime; atomicinc (__res_initstamp); } __libc_lock_unlock (lock); 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); }
int res_ninit(res_state statp) { if (statp == NULL) return -1; memset(statp, 0, sizeof(struct __res_state)); return __res_vinit(statp, 0); }
int res_init(void) { 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 = RES_DFLRETRY; if (!(_res.options & RES_INIT)) _res.options = RES_DEFAULT; return (__res_vinit(&_res, 1)); }
/* Initialize *RESP if RES_INIT is not yet set in RESP->options, or if res_init in some other thread requested re-initializing. */ static __attribute__ ((warn_unused_result)) bool maybe_init (struct resolv_context *ctx, bool preinit) { struct __res_state *resp = ctx->resp; if (resp->options & RES_INIT) { if (resp->options & RES_NORELOAD) /* Configuration reloading was explicitly disabled. */ return true; /* If there is no associated resolv_conf object despite the initialization, something modified *ctx->resp. Do not override those changes. */ if (ctx->conf != NULL && replicated_configuration_matches (ctx)) { struct resolv_conf *current = __resolv_conf_get_current (); if (current == NULL) return false; /* Check if the configuration changed. */ if (current != ctx->conf) { /* This call will detach the extended resolver state. */ if (resp->nscount > 0) __res_iclose (resp, true); /* Reattach the current configuration. */ if (__resolv_conf_attach (ctx->resp, current)) { __resolv_conf_put (ctx->conf); /* ctx takes ownership, so we do not release current. */ ctx->conf = current; } } else /* No change. Drop the reference count for current. */ __resolv_conf_put (current); } return true; } assert (ctx->conf == NULL); if (preinit) { if (!resp->retrans) resp->retrans = RES_TIMEOUT; if (!resp->retry) resp->retry = RES_DFLRETRY; resp->options = RES_DEFAULT; if (!resp->id) resp->id = res_randomid (); } if (__res_vinit (resp, preinit) < 0) return false; ctx->conf = __resolv_conf_get (ctx->resp); return true; }
int res_init(void) { 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_nclose (&_res); /* Close any VC sockets. */ int ns; for (ns = 0; ns < MAXNS; ns++) { free (_res._u._ext.nsaddrs[ns]); _res._u._ext.nsaddrs[ns] = NULL; } } /* * 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.id) _res.id = 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)); }
/* Initialize resp if RES_INIT is not yet set or if res_init in some other thread requested re-initializing. */ int __res_maybe_init (res_state resp, int preinit) { 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); }
int res_init(void) { extern int __res_vinit(res_state, int); unsigned int save_retrans, save_retry, save_options, save_id; struct __res_state_ext *save_ext; #ifdef USE__RES_9 _res_static = &_res_9; #else _res_static = &_res; #endif save_retrans = RES_TIMEOUT; save_retry = RES_DFLRETRY; save_options = RES_DEFAULT; save_id = res_randomid(); save_ext = _res_static->_u._ext.ext; if (_res_static->options & RES_INIT) { /* Caller wants to override default options */ save_options = _res_static->options; if (_res_static->retrans != 0) save_retrans = _res_static->retrans; if (_res_static->retry != 0) save_retry = _res_static->retry; if (_res_static->id != 0) save_id = _res_static->id; } memset(_res_static, 0, sizeof(struct __res_state)); _res_static->_vcsock = -1; _res_static->retrans = save_retrans; _res_static->retry = save_retry; _res_static->id = save_id; _res_static->options = save_options; _res_static->_u._ext.ext = save_ext; _res_static->_pad = 9; if (_res_static->_u._ext.ext == NULL) _res_static->_u._ext.ext = (struct __res_state_ext *)calloc(1, sizeof(struct __res_state_ext)); return (__res_vinit(_res_static, 1)); }
/* * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to * INADDR_ANY and the default domain name comes from the gethostname(). * * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1 * rather than INADDR_ANY ("0.0.0.0") as the default name server address * since it was noted that INADDR_ANY actually meant ``the first interface * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, * it had to be "up" in order for you to reach your own name server. It * was later decided that since the recommended practice is to always * install local static routes through 127.0.0.1 for all your network * interfaces, that we could solve this problem without a code change. * * The configuration file should always be used, since it is the only way * to specify a default domain. If you are running a server on your local * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1" * in the configuration file. * * Return 0 if completes successfully, -1 on error */ int res_ninit(res_state statp) { extern int __res_vinit(res_state, int); return (__res_vinit(statp, 0)); }
int res_init(void) { int rv; extern int __res_vinit(res_state, int); #ifdef COMPAT__RES /* * Compatibility with program that were accessing _res directly * to set options. We keep another struct res that is the same * size as the original res structure, and then copy fields to * it so that we achieve the same initialization */ extern void *__res_get_old_state(void); extern void __res_put_old_state(void *); res_state ores = __res_get_old_state(); if (ores->options != 0) _nres.options = ores->options; if (ores->retrans != 0) _nres.retrans = ores->retrans; if (ores->retry != 0) _nres.retry = ores->retry; #endif /* * 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. * * _nres.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 (!_nres.retrans) _nres.retrans = RES_TIMEOUT; if (!_nres.retry) _nres.retry = 4; if (!(_nres.options & RES_INIT)) _nres.options = RES_DEFAULT; /* * 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 (!_nres.id) _nres.id = res_randomid(); rv = __res_vinit(&_nres, 1); #ifdef COMPAT__RES __res_put_old_state(&_nres); #endif return rv; }