Skip to content

Commit

Permalink
* sysdeps/posix/getaddrinfo.c (getaddrinfo): When sorting addresses
Browse files Browse the repository at this point in the history
	and admin selects to be able to replace the gai.conf file, lock
	data structures around the qsort call.
  • Loading branch information
Ulrich Drepper committed Oct 17, 2007
1 parent 406f28d commit fc4837e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2007-10-17 Jakub Jelinek <jakub@redhat.com>

* sysdeps/posix/getaddrinfo.c (getaddrinfo): When sorting addresses
and admin selects to be able to replace the gai.conf file, lock
data structures around the qsort call.

2007-10-17 Ulrich Drepper <drepper@redhat.com>

* sysdeps/x86_64/cacheinfo.c: Comment out code added in support of
Expand Down
27 changes: 21 additions & 6 deletions sysdeps/posix/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,10 +1426,13 @@ in6aicmp (const void *p1, const void *p2)
#define GAICONF_FNAME "/etc/gai.conf"


/* Nozero if we are supposed to reload the config file automatically
/* Non-zero if we are supposed to reload the config file automatically
whenever it changed. */
static int gaiconf_reload_flag;

/* Non-zero if gaiconf_reload_flag was ever set to true. */
static int gaiconf_reload_flag_ever_set;

/* Last modification time. */
static struct timespec gaiconf_mtime;

Expand Down Expand Up @@ -1611,7 +1614,11 @@ gaiconf_init (void)

case 6:
if (strcmp (cmd, "reload") == 0)
gaiconf_reload_flag = strcmp (val1, "yes") == 0;
{
gaiconf_reload_flag = strcmp (val1, "yes") == 0;
if (gaiconf_reload_flag)
gaiconf_reload_flag_ever_set = 1;
}
break;

case 10:
Expand Down Expand Up @@ -1934,9 +1941,6 @@ getaddrinfo (const char *name, const char *service,
__libc_once_define (static, once);
__typeof (once) old_once = once;
__libc_once (once, gaiconf_init);
if (old_once && gaiconf_reload_flag)
gaiconf_reload ();

/* Sort results according to RFC 3484. */
struct sort_result results[nresults];
struct addrinfo *q;
Expand Down Expand Up @@ -2055,7 +2059,18 @@ getaddrinfo (const char *name, const char *service,

/* We got all the source addresses we can get, now sort using
the information. */
qsort (results, nresults, sizeof (results[0]), rfc3484_sort);
if (__builtin_expect (gaiconf_reload_flag_ever_set, 0))
{
__libc_lock_define_initialized (static, lock);

__libc_lock_lock (lock);
if (old_once && gaiconf_reload_flag)
gaiconf_reload ();
qsort (results, nresults, sizeof (results[0]), rfc3484_sort);
__libc_lock_unlock (lock);
}
else
qsort (results, nresults, sizeof (results[0]), rfc3484_sort);

/* Queue the results up as they come out of sorting. */
q = p = results[0].dest_addr;
Expand Down

0 comments on commit fc4837e

Please sign in to comment.