]> git.ipfire.org Git - thirdparty/glibc.git/blame - resolv/res_libc.c
hurd: Fix build
[thirdparty/glibc.git] / resolv / res_libc.c
CommitLineData
b87d4739 1/* Definitions related to res_init linked into libc instead of libresolv.
04277e02 2 Copyright (C) 1995-2019 Free Software Foundation, Inc.
b87d4739
FW
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
b43b13ac
UD
19/*
20 * Copyright (c) 1995-1999 by Internet Software Consortium.
21 *
22 * Permission to use, copy, modify, and distribute this software for any
23 * purpose with or without fee is hereby granted, provided that the above
24 * copyright notice and this permission notice appear in all copies.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
27 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
29 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
30 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
31 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
32 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
33 * SOFTWARE.
34 */
35
9e365fe7 36#include <atomic.h>
87bb6b6c 37#include <limits.h>
b43b13ac 38#include <sys/types.h>
b43b13ac 39#include <netinet/in.h>
b43b13ac 40#include <arpa/nameser.h>
b43b13ac 41#include <resolv.h>
ec999b8e 42#include <libc-lock.h>
b1e7c13c 43#include <resolv-internal.h>
b43b13ac 44
b43b13ac 45int
b87d4739
FW
46res_init (void)
47{
48 /* These three fields used to be statically initialized. This made
49 it hard to use this code in a shared library. It is necessary,
50 now that we're doing dynamic initialization here, that we
51 preserve the old semantics: if an application modifies one of
52 these three fields of _res before res_init is called,
53 res_init will not alter them. Of course, if an application is
54 setting them to _zero_ before calling res_init, hoping to
55 override what used to be the static default, we can't detect it
56 and unexpected results will follow. Zero for any of these fields
57 would make no sense, so one can safely assume that the
58 applications were already getting unexpected results.
59
60 _res.options is tricky since some apps were known to diddle the
61 bits before res_init was first called. We can't replicate that
62 semantic with dynamic initialization (they may have turned bits
63 off that are set in RES_DEFAULT). Our solution is to declare
64 such applications "broken". They could fool us by setting
65 RES_INIT but none do (yet). */
66 if (!_res.retrans)
67 _res.retrans = RES_TIMEOUT;
68 if (!_res.retry)
69 _res.retry = RES_DFLRETRY;
70 if (!(_res.options & RES_INIT))
71 _res.options = RES_DEFAULT;
72 else if (_res.nscount > 0)
73 __res_iclose (&_res, true); /* Close any VC sockets. */
74
75 /* This one used to initialize implicitly to zero, so unless the app
76 has set it to something in particular, we can randomize it *
77 now. */
78 if (!_res.id)
79 _res.id = res_randomid ();
80
b87d4739 81 return __res_vinit (&_res, 1);
b43b13ac 82}
e685e07d 83\f
4aeb650e
RM
84/* This needs to be after the use of _res in res_init, above. */
85#undef _res
86
1f503475
UD
87/* The resolver state for use by single-threaded programs.
88 This differs from plain `struct __res_state _res;' in that it doesn't
89 create a common definition, but a plain symbol that resides in .bss,
90 which can have an alias. */
fb431262 91struct __res_state _res __attribute__ ((nocommon));
0e9d6240 92
0e9d6240
UD
93#undef __resp
94__thread struct __res_state *__resp = &_res;
95extern __thread struct __res_state *__libc_resp
96 __attribute__ ((alias ("__resp"))) attribute_hidden;
0e9d6240 97
82f43dd2
ZW
98#include <shlib-compat.h>
99
4aeb650e
RM
100/* We declare this with compat_symbol so that it's not
101 visible at link time. Programs must use the accessor functions. */
3f2e46a4 102#ifdef SHARED
4aeb650e 103compat_symbol (libc, _res, _res, GLIBC_2_0);
4aeb650e 104#endif
b43b13ac 105
b87d4739 106#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
e685e07d 107# undef res_init
1cb990bc 108extern int __res_init_weak (void);
0e3af135 109weak_extern (__res_init_weak);
1cb990bc 110strong_alias (__res_init, __res_init_weak);
0e3af135 111compat_symbol (libc, __res_init_weak, res_init, GLIBC_2_0);
e685e07d 112#endif