]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* nscd/nscd-client.h: Include sys/uio.h.
authorUlrich Drepper <drepper@redhat.com>
Tue, 22 Feb 2005 22:58:32 +0000 (22:58 +0000)
committerUlrich Drepper <drepper@redhat.com>
Tue, 22 Feb 2005 22:58:32 +0000 (22:58 +0000)
(__readall, __readvall, writeall): New prototypes.
* nscd/connections.c (writeall): New function.
(handle_request): Use it.
* nscd/aicache.c (addhstaiX): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nscd/hstcache.c (cache_addhst): Likewise.
* nscd/grpcache.c (cache_addgr): Likewise.
* nscd/pwdcache.c (cache_addpw): Likewise.
* nscd/nscd_helper.c (__readall, __readvall): New functions.
* nscd/nscd_getai.c (__nscd_getai): Use them.
* nscd/nscd_getpw_r.c (__nscd_getpw_r): Likewise.
* nscd/nscd_getgr_r.c (__nscd_getgr_r): Likewise.
* nscd/nscd_gethst_r.c (__nscd_gethst_r): Likewise.
* nscd/nscd_initgroups.c (__nscd_getgrouplist): Likewise.

13 files changed:
ChangeLog
nscd/aicache.c
nscd/connections.c
nscd/grpcache.c
nscd/hstcache.c
nscd/initgrcache.c
nscd/nscd_getai.c
nscd/nscd_getgr_r.c
nscd/nscd_gethst_r.c
nscd/nscd_getpw_r.c
nscd/nscd_helper.c
nscd/nscd_initgroups.c
nscd/pwdcache.c

index da351f3479b5264df3cf79aaea7b477615df6d1d..02c97da4e3c62b4d51e5e1f8b8e06a79404d8d84 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2005-02-22  Jakub Jelinek  <jakub@redhat.com>
+
+       * nscd/nscd-client.h: Include sys/uio.h.
+       (__readall, __readvall, writeall): New prototypes.
+       * nscd/connections.c (writeall): New function.
+       (handle_request): Use it.
+       * nscd/aicache.c (addhstaiX): Likewise.
+       * nscd/initgrcache.c (addinitgroupsX): Likewise.
+       * nscd/hstcache.c (cache_addhst): Likewise.
+       * nscd/grpcache.c (cache_addgr): Likewise.
+       * nscd/pwdcache.c (cache_addpw): Likewise.
+       * nscd/nscd_helper.c (__readall, __readvall): New functions.
+       * nscd/nscd_getai.c (__nscd_getai): Use them.
+       * nscd/nscd_getpw_r.c (__nscd_getpw_r): Likewise.
+       * nscd/nscd_getgr_r.c (__nscd_getgr_r): Likewise.
+       * nscd/nscd_gethst_r.c (__nscd_gethst_r): Likewise.
+       * nscd/nscd_initgroups.c (__nscd_getgrouplist): Likewise.
+
 2005-02-22  Roland McGrath  <roland@redhat.com>
 
        * include/sys/socket.h: Declare __recv.
index 4e0496ff44be0d3ac9f1ca23a916d9be2962ff90..bdd2a9b371ed7e33ecc92dc3871c7bfcf024ef81 100644 (file)
@@ -1,5 +1,5 @@
 /* Cache handling for host lookup.
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -365,7 +365,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
                     wait.  */
                  assert (fd != -1);
 
-                 TEMP_FAILURE_RETRY (write (fd, &dataset->resp, total));
+                 writeall (fd, &dataset->resp, total);
                }
 
              goto out;
index 63a01e3bb6bffb7249cab3e88db5d9468abd791e..86069b237a425fe3d7f9fef44558b412c240bd2a 100644 (file)
@@ -181,13 +181,28 @@ static int sock;
 unsigned long int client_queued;
 
 
+ssize_t
+writeall (int fd, const void *buf, size_t len)
+{
+  size_t n = len;
+  ssize_t ret;
+  do
+    {
+      ret = TEMP_FAILURE_RETRY (write (fd, buf, n));
+      if (ret <= 0)
+       break;
+      buf = (const char *) buf + ret;
+      n -= ret;
+    }
+  while (n > 0);
+  return ret < 0 ? ret : len - n;
+}
+
+
 /* Initialize database information structures.  */
 void
 nscd_init (void)
 {
-  struct sockaddr_un sock_addr;
-  size_t cnt;
-
   /* Secure mode and unprivileged mode are incompatible */
   if (server_user != NULL && secure_in_use)
     {
@@ -204,7 +219,7 @@ nscd_init (void)
     /* No configuration for this value, assume a default.  */
     nthreads = 2 * lastdb;
 
-  for (cnt = 0; cnt < lastdb; ++cnt)
+  for (size_t cnt = 0; cnt < lastdb; ++cnt)
     if (dbs[cnt].enabled)
       {
        pthread_rwlock_init (&dbs[cnt].lock, NULL);
@@ -500,6 +515,7 @@ cannot set socket to close on exec: %s; disabling paranoia mode"),
       exit (1);
     }
   /* Bind a name to the socket.  */
+  struct sockaddr_un sock_addr;
   sock_addr.sun_family = AF_UNIX;
   strcpy (sock_addr.sun_path, _PATH_NSCDSOCKET);
   if (bind (sock, (struct sockaddr *) &sock_addr, sizeof (sock_addr)) < 0)
@@ -691,7 +707,7 @@ cannot handle old request version %d; current version is %d"),
       if (cached != NULL)
        {
          /* Hurray it's in the cache.  */
-         if (TEMP_FAILURE_RETRY (write (fd, cached->data, cached->recsize))
+         if (writeall (fd, cached->data, cached->recsize)
              != cached->recsize
              && __builtin_expect (debug_level, 0) > 0)
            {
index ed84d92120dbb3758edbc6574d66a5eefd66c4c0..5d327f360cbb92ac1d5c8bd55d2e49a86d9db029 100644 (file)
@@ -292,7 +292,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
             unnecessarily let the receiver wait.  */
          assert (fd != -1);
 
-         written = TEMP_FAILURE_RETRY (write (fd, &dataset->resp, total));
+         written = writeall (fd, &dataset->resp, total);
        }
 
       /* Add the record to the database.  But only if it has not been
index a18860a53dda87a9fa8b9247476a09d1c64455a3..377f02387d297acb188d84912907eca98cf744b1 100644 (file)
@@ -327,7 +327,7 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
             unnecessarily keep the receiver waiting.  */
          assert (fd != -1);
 
-         written = TEMP_FAILURE_RETRY (write (fd, &dataset->resp, total));
+         written = writeall (fd, &dataset->resp, total);
        }
 
       /* Add the record to the database.  But only if it has not been
index b46433716b534f6d98bc1fa78248f1cf53898553..db01f1bc28c5eaeb21a7353f04fe1e8cb2252c5e 100644 (file)
@@ -1,5 +1,5 @@
 /* Cache handling for host lookup.
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -343,7 +343,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
             unnecessarily let the receiver wait.  */
          assert (fd != -1);
 
-         written = TEMP_FAILURE_RETRY (write (fd, &dataset->resp, total));
+         written = writeall (fd, &dataset->resp, total);
        }
 
 
index 866f7b2a5feb3a99f4e6c344b084fb67716a34a1..4e3dfad1ea4a14e06d9864f9a12b2b5658f18bcc 100644 (file)
@@ -119,8 +119,7 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop)
       if (respdata == NULL)
        {
          /* Read the data from the socket.  */
-         if ((size_t) TEMP_FAILURE_RETRY (__read (sock, resultbuf + 1,
-                                                  datalen)) == datalen)
+         if ((size_t) __readall (sock, resultbuf + 1, datalen) == datalen)
            {
              retval = 0;
              *result = resultbuf;
index 282912db3e5dee8d731ceadc44c38ef0426f1528..dae1c0da54e61f120fd5ab7d879c2dc8af14c20f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
+/* Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1998.
@@ -202,7 +202,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
          total_len = vec[0].iov_len + vec[1].iov_len;
 
          /* Get this data.  */
-         size_t n = TEMP_FAILURE_RETRY (__readv (sock, vec, 2));
+         size_t n = __readvall (sock, vec, 2);
          if (__builtin_expect (n != total_len, 0))
            goto out_close;
        }
@@ -232,8 +232,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
       retval = 0;
       if (gr_name == NULL)
        {
-         size_t n = TEMP_FAILURE_RETRY (__read (sock, resultbuf->gr_mem[0],
-                                                total_len));
+         size_t n = __readall (sock, resultbuf->gr_mem[0], total_len);
          if (__builtin_expect (n != total_len, 0))
            {
              /* The `errno' to some value != ERANGE.  */
index ef27e68735e016f9a0d71357380b809d2b29a7c7..70ee38b71f286afe3122a433ae8ad8d00c04f79f 100644 (file)
@@ -299,8 +299,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
              ++n;
            }
 
-         if ((size_t) TEMP_FAILURE_RETRY (__readv (sock, vec, n))
-             != total_len)
+         if ((size_t) __readvall (sock, vec, n) != total_len)
            goto out_close;
        }
       else
@@ -329,9 +328,8 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
       /* And finally read the aliases.  */
       if (addr_list == NULL)
        {
-         if ((size_t) TEMP_FAILURE_RETRY (__read (sock,
-                                                  resultbuf->h_aliases[0],
-                                                  total_len)) == total_len)
+         if ((size_t) __readall (sock, resultbuf->h_aliases[0], total_len)
+             == total_len)
            {
              retval = 0;
              *result = resultbuf;
index fe5fb43ca1001265125450b82deb1b0ace80f1b1..61a712c6b41b8b5c83dbc4d96c1072cc6d8780c2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1998.
 
@@ -172,7 +172,7 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
       retval = 0;
       if (pw_name == NULL)
        {
-         ssize_t nbytes = TEMP_FAILURE_RETRY (__read (sock, buffer, total));
+         ssize_t nbytes = __readall (sock, buffer, total);
 
          if (__builtin_expect (nbytes != total, 0))
            {
index ea4fb968dbd61d2fb6dd1bf02474c45e18d0cd50..c99cb430aa5fc61a6a3c1deff81ca1e89be7acfe 100644 (file)
 #include "nscd-client.h"
 
 
+ssize_t
+__readall (int fd, void *buf, size_t len)
+{
+  size_t n = len;
+  ssize_t ret;
+  do
+    {
+      ret = TEMP_FAILURE_RETRY (__read (fd, buf, n));
+      if (ret <= 0)
+       break;
+      buf = (char *) buf + ret;
+      n -= ret;
+    }
+  while (n > 0);
+  return ret < 0 ? ret : len - n;
+}
+
+
+ssize_t
+__readvall (int fd, const struct iovec *iov, int iovcnt)
+{
+  ssize_t ret = TEMP_FAILURE_RETRY (__readv (fd, iov, iovcnt));
+  if (ret <= 0)
+    return ret;
+
+  size_t total = 0;
+  for (int i = 0; i < iovcnt; ++i)
+    total += iov[i].iov_len;
+
+  if (ret < total)
+    {
+      struct iovec iov_buf[iovcnt];
+      ssize_t r = ret;
+
+      struct iovec *iovp = memcpy (iov_buf, iov, iovcnt * sizeof (*iov));
+      do
+       {
+         while (iovp->iov_len <= r)
+           {
+             r -= iovp->iov_len;
+             --iovcnt;
+             ++iovp;
+           }
+         iovp->iov_base = (char *) iovp->iov_base + r;
+         iovp->iov_len -= r;
+         r = TEMP_FAILURE_RETRY (__readv (fd, iovp, iovcnt));
+         if (r <= 0)
+           break;
+         ret += r;
+       }
+      while (ret < total);
+      if (r < 0)
+       ret = r;
+    }
+  return ret;
+}
+
+
 static int
 open_socket (void)
 {
index daddf2e164f28885992ab2fa925224b0dafcd72b..cf5af6edc1bb55d7a3ca71607a16dbe81182e418 100644 (file)
@@ -110,9 +110,8 @@ __nscd_getgrouplist (const char *user, gid_t group, long int *size,
       if (respdata == NULL)
        {
          /* Read the data from the socket.  */
-         if ((size_t) TEMP_FAILURE_RETRY (__read (sock, *groupsp,
-                                                  initgr_resp->ngrps
-                                                  * sizeof (gid_t)))
+         if ((size_t) __readall (sock, *groupsp, initgr_resp->ngrps
+                                                 * sizeof (gid_t))
              == initgr_resp->ngrps * sizeof (gid_t))
            retval = initgr_resp->ngrps;
        }
index b67b0f2b435c397fd160ec7cc844caa0808a5bb7..34265c3f39a12ffb8e6b0359217f222fedda09c2 100644 (file)
@@ -287,7 +287,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
             unnecessarily let the receiver wait.  */
          assert (fd != -1);
 
-         written = TEMP_FAILURE_RETRY (write (fd, &dataset->resp, total));
+         written = writeall (fd, &dataset->resp, total);
        }