+2016-08-18 Torvald Riegel <triegel@redhat.com>
+
+ [BZ #20477]
+ * resolv/res_hconf.c (do_init): Use atomic access.
+ * resolv/res_hconf.h: Add comments.
+ * nscd/aicache.c (addhstaiX): Call _res_hconf_init unconditionally.
+ * nss/getXXbyYY_r.c (REENTRANT_NAME): Likewise.
+ * sysdeps/posix/getaddrinfo.c (gaih_inet): Likewise.
+
2016-08-18 Stefan Liebler <stli@linux.vnet.ibm.com>
* sysdeps/ieee754/dbl-64/k_rem_pio2.c (__kernel_rem_pio2):
nip = hosts_database;
/* Initialize configurations. */
- if (__glibc_unlikely (!_res_hconf.initialized))
- _res_hconf_init ();
+ _res_hconf_init ();
if (__res_maybe_init (&_res, 0) == -1)
no_more = 1;
}
#endif /* need _res */
#ifdef NEED__RES_HCONF
- if (!_res_hconf.initialized)
- _res_hconf_init ();
+ _res_hconf_init ();
#endif /* need _res_hconf */
void *tmp_ptr = fct.l;
arg_trimdomain_list (ENV_TRIM_OVERR, 1, envval);
}
- _res_hconf.initialized = 1;
+ /* See comments on the declaration of _res_hconf. */
+ atomic_store_release (&_res_hconf.initialized, 1);
}
struct hconf
{
+ /* We keep the INITIALIZED member only for backwards compatibility. New
+ code should just call _res_hconf_init unconditionally. For this field
+ to be used safely, users must ensure that either (1) a call to
+ _res_hconf_init happens-before any load from INITIALIZED, or (2) an
+ assignment of zero to INITIALIZED happens-before any load from it, and
+ these loads use acquire MO if the intent is to skip calling
+ _res_hconf_init if the load returns a nonzero value. Such acquire MO
+ loads will then synchronize with the release MO store to INITIALIZED
+ in do_init in res_hconf.c; see pthread_once for more detail. */
int initialized;
int unused1;
int unused2[4];
nip = __nss_hosts_database;
/* Initialize configurations. */
- if (__glibc_unlikely (!_res_hconf.initialized))
- _res_hconf_init ();
+ _res_hconf_init ();
if (__res_maybe_init (&_res, 0) == -1)
no_more = 1;