[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commits] r4307 - in /fsf/trunk/libc: ./ locale/programs/ nis/nss_compat/ nscd/ resolv/ sysdeps/unix/sysv/linux/
- To: commits@xxxxxxxxxx
- Subject: [commits] r4307 - in /fsf/trunk/libc: ./ locale/programs/ nis/nss_compat/ nscd/ resolv/ sysdeps/unix/sysv/linux/
- From: eglibc@xxxxxxxxxx
- Date: Fri, 23 Nov 2007 08:04:01 -0000
Author: eglibc
Date: Fri Nov 23 00:03:59 2007
New Revision: 4307
Log:
Import glibc-mainline for 2007-11-23
Modified:
fsf/trunk/libc/ChangeLog
fsf/trunk/libc/locale/programs/ld-collate.c
fsf/trunk/libc/nis/nss_compat/compat-initgroups.c
fsf/trunk/libc/nscd/connections.c
fsf/trunk/libc/nscd/mem.c
fsf/trunk/libc/nscd/nscd.h
fsf/trunk/libc/resolv/res_hconf.c
fsf/trunk/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c
Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Fri Nov 23 00:03:59 2007
@@ -1,3 +1,28 @@
+2007-11-22 Ulrich Drepper <drepper@xxxxxxxxxx>
+
+ [BZ #5382]
+ * nscd/nscd.h (NSCD_THREAD_STACKSIZE): Define.
+ * nscd/connections.c (start_threads): Use NSCD_THREAD_STACKSIZE.
+ * nscd/mem.c (gc): Don't allocate arrays on stack if it can
+ overflow it.
+ Partially based on a patch by Petr Baudis <pasky@xxxxxxx>.
+
+ * sysdeps/unix/sysv/linux/nscd_setup_thread.c (setup_thread):
+ Return zero in case thread library is not NPTL.
+
+ [BZ #5375]
+ * resolv/res_hconf.c (_res_hconf_reorder_addrs): Fix locking when
+ initializing interface list.
+
+ [BZ #5378]
+ * nis/nss_compat/compat-initgroups.c (getgrent_next_nss): Don't
+ use result of nss_getgrgid_r if nothing was found. For other
+ error return with a failure.
+ Partially based on a patch by Petr Baudis <pasky@xxxxxxx>.
+
+ * locale/programs/ld-collate.c (collate_read): Fix loop to match
+ macro name.
+
2007-11-19 Ulrich Drepper <drepper@xxxxxxxxxx>
* sysdeps/posix/getaddrinfo.c (defaults_scopes, scopes): New variables.
Modified: fsf/trunk/libc/locale/programs/ld-collate.c
==============================================================================
--- fsf/trunk/libc/locale/programs/ld-collate.c (original)
+++ fsf/trunk/libc/locale/programs/ld-collate.c Fri Nov 23 00:03:59 2007
@@ -4008,6 +4008,8 @@
arg->val.str.lenmb) == 0
&& curdef->str[arg->val.str.lenmb] == '\0')
break;
+ else
+ curdef = curdef->next;
if ((nowtok == tok_ifdef && curdef != NULL)
|| (nowtok == tok_ifndef && curdef == NULL))
Modified: fsf/trunk/libc/nis/nss_compat/compat-initgroups.c
==============================================================================
--- fsf/trunk/libc/nis/nss_compat/compat-initgroups.c (original)
+++ fsf/trunk/libc/nis/nss_compat/compat-initgroups.c Fri Nov 23 00:03:59 2007
@@ -303,10 +303,19 @@
else
tmpbuf = extend_alloca (tmpbuf, tmplen, 2 * tmplen);
- if (!in_blacklist (grpbuf.gr_name,
- strlen (grpbuf.gr_name), ent))
- check_and_add_group (user, group, start, size, groupsp,
- limit, &grpbuf);
+ if (__builtin_expect (status != NSS_STATUS_NOTFOUND, 1))
+ {
+ if (__builtin_expect (status != NSS_STATUS_SUCCESS, 0))
+ {
+ free (mygroups);
+ return status;
+ }
+
+ if (!in_blacklist (grpbuf.gr_name,
+ strlen (grpbuf.gr_name), ent))
+ check_and_add_group (user, group, start, size, groupsp,
+ limit, &grpbuf);
+ }
}
free (mygroups);
Modified: fsf/trunk/libc/nscd/connections.c
==============================================================================
--- fsf/trunk/libc/nscd/connections.c (original)
+++ fsf/trunk/libc/nscd/connections.c Fri Nov 23 00:03:59 2007
@@ -1840,7 +1840,7 @@
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
/* Use 1MB stacks, twice as much for 64-bit architectures. */
- pthread_attr_setstacksize (&attr, 1024 * 1024 * (sizeof (void *) / 4));
+ pthread_attr_setstacksize (&attr, NSCD_THREAD_STACKSIZE);
/* We allow less than LASTDB threads only for debugging. */
if (debug_level == 0)
Modified: fsf/trunk/libc/nscd/mem.c
==============================================================================
--- fsf/trunk/libc/nscd/mem.c (original)
+++ fsf/trunk/libc/nscd/mem.c Fri Nov 23 00:03:59 2007
@@ -34,6 +34,11 @@
#include "nscd.h"
+/* Wrapper functions with error checking for standard functions. */
+extern void *xmalloc (size_t n);
+extern void *xcalloc (size_t n, size_t s);
+
+
static int
sort_he (const void *p1, const void *p2)
{
@@ -69,6 +74,10 @@
#define ALLBITS ((((BITMAP_T) 1) << BITS) - 1)
#define HIGHBIT (((BITMAP_T) 1) << (BITS - 1))
+/* Maximum size of stack frames we allow the thread to use. We use
+ 80% of the thread stack size. */
+#define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10)
+
static void
markrange (BITMAP_T *mark, ref_t start, size_t len)
@@ -117,13 +126,43 @@
we have to look at the memory. We use a mark and sweep algorithm
where the marks are placed in this array. */
assert (db->head->first_free % BLOCK_ALIGN == 0);
- BITMAP_T mark[(db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS];
- memset (mark, '\0', sizeof (mark));
+
+ BITMAP_T *mark;
+ bool mark_use_malloc;
+ size_t stack_used = 0;
+ size_t memory_needed = ((db->head->first_free / BLOCK_ALIGN + BITS - 1)
+ / BITS) * sizeof (BITMAP_T);
+ if (memory_needed <= MAX_STACK_USE)
+ {
+ mark = (BITMAP_T *) alloca (memory_needed);
+ mark_use_malloc = false;
+ memset (mark, '\0', memory_needed);
+ stack_used = memory_needed;
+ }
+ else
+ {
+ mark = (BITMAP_T *) xcalloc (1, memory_needed);
+ mark_use_malloc = true;
+ }
/* Create an array which can hold pointer to all the entries in hash
entries. */
- struct hashentry *he[db->head->nentries];
- struct hashentry *he_data[db->head->nentries];
+ memory_needed = 2 * db->head->nentries * sizeof (struct hashentry *);
+ struct hashentry **he;
+ struct hashentry **he_data;
+ bool he_use_malloc;
+ if (stack_used + memory_needed <= MAX_STACK_USE)
+ {
+ he = alloca (db->head->nentries * sizeof (struct hashentry *));
+ he_data = alloca (db->head->nentries * sizeof (struct hashentry *));
+ he_use_malloc = false;
+ }
+ else
+ {
+ he = xmalloc (memory_needed);
+ he_data = &he[db->head->nentries * sizeof (struct hashentry *)];
+ he_use_malloc = true;
+ }
size_t cnt = 0;
for (size_t idx = 0; idx < db->head->module; ++idx)
@@ -455,6 +494,11 @@
out:
pthread_mutex_unlock (&db->memlock);
pthread_rwlock_unlock (&db->lock);
+
+ if (he_use_malloc)
+ free (he);
+ if (mark_use_malloc)
+ free (mark);
}
@@ -481,7 +525,8 @@
{
/* Try to resize the database. Grow size of 1/8th. */
size_t oldtotal = (sizeof (struct database_pers_head)
- + roundup (db->head->module * sizeof (ref_t), ALIGN)
+ + roundup (db->head->module * sizeof (ref_t),
+ ALIGN)
+ db->head->data_size);
size_t new_data_size = (db->head->data_size
+ MAX (2 * len, db->head->data_size / 8));
Modified: fsf/trunk/libc/nscd/nscd.h
==============================================================================
--- fsf/trunk/libc/nscd/nscd.h (original)
+++ fsf/trunk/libc/nscd/nscd.h Fri Nov 23 00:03:59 2007
@@ -53,6 +53,10 @@
/* Time before restarting the process in paranoia mode. */
#define RESTART_INTERVAL (60 * 60)
+
+
+/* Stack size for worker threads. */
+#define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4)
/* Structure describing dynamic part of one database. */
Modified: fsf/trunk/libc/resolv/res_hconf.c
==============================================================================
--- fsf/trunk/libc/resolv/res_hconf.c (original)
+++ fsf/trunk/libc/resolv/res_hconf.c Fri Nov 23 00:03:59 2007
@@ -377,9 +377,6 @@
} u;
} *ifaddrs);
-/* We need to protect the dynamic buffer handling. */
-__libc_lock_define_initialized (static, lock);
-
/* Reorder addresses returned in a hostent such that the first address
is an address on the local subnet, if there is such an address.
Otherwise, nothing is changed.
@@ -393,6 +390,8 @@
int i, j;
/* Number of interfaces. */
static int num_ifs = -1;
+ /* We need to protect the dynamic buffer handling. */
+ __libc_lock_define_initialized (static, lock);
/* Only reorder if we're supposed to. */
if ((_res_hconf.flags & HCONF_FLAG_REORDER) == 0)
@@ -411,8 +410,6 @@
/* Initialize interface table. */
- num_ifs = 0;
-
/* The SIOCGIFNETMASK ioctl will only work on an AF_INET socket. */
sd = __socket (AF_INET, SOCK_DGRAM, 0);
if (sd < 0)
@@ -421,45 +418,56 @@
/* Get lock. */
__libc_lock_lock (lock);
- /* Get a list of interfaces. */
- __ifreq (&ifr, &num, sd);
- if (!ifr)
- goto cleanup;
-
- ifaddrs = malloc (num * sizeof (ifaddrs[0]));
- if (!ifaddrs)
- goto cleanup1;
-
- /* Copy usable interfaces in ifaddrs structure. */
- for (cur_ifr = ifr, i = 0; i < num; cur_ifr = __if_nextreq (cur_ifr), ++i)
- {
- if (cur_ifr->ifr_addr.sa_family != AF_INET)
- continue;
-
- ifaddrs[num_ifs].addrtype = AF_INET;
- ifaddrs[num_ifs].u.ipv4.addr =
- ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr;
-
- if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0)
- continue;
-
- ifaddrs[num_ifs].u.ipv4.mask =
- ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr;
-
- /* Now we're committed to this entry. */
- ++num_ifs;
- }
- /* Just keep enough memory to hold all the interfaces we want. */
- ifaddrs = realloc (ifaddrs, num_ifs * sizeof (ifaddrs[0]));
- assert (ifaddrs != NULL);
-
- cleanup1:
- __if_freereq (ifr, num);
-
- cleanup:
- /* Release lock, preserve error value, and close socket. */
- save = errno;
- __libc_lock_unlock (lock);
+ /* Recheck, somebody else might have done the work by done. */
+ if (num_ifs <= 0)
+ {
+ int new_num_ifs = 0;
+
+ /* Get a list of interfaces. */
+ __ifreq (&ifr, &num, sd);
+ if (!ifr)
+ goto cleanup;
+
+ ifaddrs = malloc (num * sizeof (ifaddrs[0]));
+ if (!ifaddrs)
+ goto cleanup1;
+
+ /* Copy usable interfaces in ifaddrs structure. */
+ for (cur_ifr = ifr, i = 0; i < num;
+ cur_ifr = __if_nextreq (cur_ifr), ++i)
+ {
+ if (cur_ifr->ifr_addr.sa_family != AF_INET)
+ continue;
+
+ ifaddrs[new_num_ifs].addrtype = AF_INET;
+ ifaddrs[new_num_ifs].u.ipv4.addr =
+ ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr;
+
+ if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0)
+ continue;
+
+ ifaddrs[new_num_ifs].u.ipv4.mask =
+ ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr;
+
+ /* Now we're committed to this entry. */
+ ++new_num_ifs;
+ }
+ /* Just keep enough memory to hold all the interfaces we want. */
+ ifaddrs = realloc (ifaddrs, new_num_ifs * sizeof (ifaddrs[0]));
+ assert (ifaddrs != NULL);
+
+ cleanup1:
+ __if_freereq (ifr, num);
+
+ cleanup:
+ /* Release lock, preserve error value, and close socket. */
+ save = errno;
+
+ num_ifs = new_num_ifs;
+
+ __libc_lock_unlock (lock);
+ }
+
__close (sd);
}
Modified: fsf/trunk/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c
==============================================================================
--- fsf/trunk/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c (original)
+++ fsf/trunk/libc/sysdeps/unix/sysv/linux/nscd_setup_thread.c Fri Nov 23 00:03:59 2007
@@ -31,7 +31,7 @@
char buf[100];
if (confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof (buf)) >= sizeof (buf)
|| strncmp (buf, "NPTL", 4) != 0)
- return;
+ return 0;
/* Do not try this at home, kids. We play with the SETTID address
even thought the process is multi-threaded. This can only work