|
Packit |
6c4009 |
/* Definitions related to res_init linked into libc instead of libresolv.
|
|
Packit |
6c4009 |
Copyright (C) 1995-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* Copyright (c) 1995-1999 by Internet Software Consortium.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this software for any
|
|
Packit |
6c4009 |
* purpose with or without fee is hereby granted, provided that the above
|
|
Packit |
6c4009 |
* copyright notice and this permission notice appear in all copies.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
Packit |
6c4009 |
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
Packit |
6c4009 |
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
Packit |
6c4009 |
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
Packit |
6c4009 |
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
Packit |
6c4009 |
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
Packit |
6c4009 |
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
Packit |
6c4009 |
* SOFTWARE.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <atomic.h>
|
|
Packit |
6c4009 |
#include <limits.h>
|
|
Packit |
6c4009 |
#include <sys/types.h>
|
|
Packit |
6c4009 |
#include <netinet/in.h>
|
|
Packit |
6c4009 |
#include <arpa/nameser.h>
|
|
Packit |
6c4009 |
#include <resolv.h>
|
|
Packit |
6c4009 |
#include <libc-lock.h>
|
|
Packit |
6c4009 |
#include <resolv-internal.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
res_init (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* These three fields used to be statically initialized. This made
|
|
Packit |
6c4009 |
it hard to use this code in a shared library. It is necessary,
|
|
Packit |
6c4009 |
now that we're doing dynamic initialization here, that we
|
|
Packit |
6c4009 |
preserve the old semantics: if an application modifies one of
|
|
Packit |
6c4009 |
these three fields of _res before res_init is called,
|
|
Packit |
6c4009 |
res_init will not alter them. Of course, if an application is
|
|
Packit |
6c4009 |
setting them to _zero_ before calling res_init, hoping to
|
|
Packit |
6c4009 |
override what used to be the static default, we can't detect it
|
|
Packit |
6c4009 |
and unexpected results will follow. Zero for any of these fields
|
|
Packit |
6c4009 |
would make no sense, so one can safely assume that the
|
|
Packit |
6c4009 |
applications were already getting unexpected results.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_res.options is tricky since some apps were known to diddle the
|
|
Packit |
6c4009 |
bits before res_init was first called. We can't replicate that
|
|
Packit |
6c4009 |
semantic with dynamic initialization (they may have turned bits
|
|
Packit |
6c4009 |
off that are set in RES_DEFAULT). Our solution is to declare
|
|
Packit |
6c4009 |
such applications "broken". They could fool us by setting
|
|
Packit |
6c4009 |
RES_INIT but none do (yet). */
|
|
Packit |
6c4009 |
if (!_res.retrans)
|
|
Packit |
6c4009 |
_res.retrans = RES_TIMEOUT;
|
|
Packit |
6c4009 |
if (!_res.retry)
|
|
Packit |
6c4009 |
_res.retry = RES_DFLRETRY;
|
|
Packit |
6c4009 |
if (!(_res.options & RES_INIT))
|
|
Packit |
6c4009 |
_res.options = RES_DEFAULT;
|
|
Packit |
6c4009 |
else if (_res.nscount > 0)
|
|
Packit |
6c4009 |
__res_iclose (&_res, true); /* Close any VC sockets. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This one used to initialize implicitly to zero, so unless the app
|
|
Packit |
6c4009 |
has set it to something in particular, we can randomize it *
|
|
Packit |
6c4009 |
now. */
|
|
Packit |
6c4009 |
if (!_res.id)
|
|
Packit |
6c4009 |
_res.id = res_randomid ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return __res_vinit (&_res, 1);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This needs to be after the use of _res in res_init, above. */
|
|
Packit |
6c4009 |
#undef _res
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The resolver state for use by single-threaded programs.
|
|
Packit |
6c4009 |
This differs from plain `struct __res_state _res;' in that it doesn't
|
|
Packit |
6c4009 |
create a common definition, but a plain symbol that resides in .bss,
|
|
Packit |
6c4009 |
which can have an alias. */
|
|
Packit |
6c4009 |
struct __res_state _res __attribute__ ((nocommon));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef __resp
|
|
Packit |
6c4009 |
__thread struct __res_state *__resp = &_res;
|
|
Packit |
6c4009 |
extern __thread struct __res_state *__libc_resp
|
|
Packit |
6c4009 |
__attribute__ ((alias ("__resp"))) attribute_hidden;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <shlib-compat.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We declare this with compat_symbol so that it's not
|
|
Packit |
6c4009 |
visible at link time. Programs must use the accessor functions. */
|
|
Packit |
6c4009 |
#ifdef SHARED
|
|
Packit |
6c4009 |
compat_symbol (libc, _res, _res, GLIBC_2_0);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
|
|
Packit |
6c4009 |
# undef res_init
|
|
Packit |
6c4009 |
extern int __res_init_weak (void);
|
|
Packit |
6c4009 |
weak_extern (__res_init_weak);
|
|
Packit |
6c4009 |
strong_alias (__res_init, __res_init_weak);
|
|
Packit |
6c4009 |
compat_symbol (libc, __res_init_weak, res_init, GLIBC_2_0);
|
|
Packit |
6c4009 |
#endif
|