mirror of git://sourceware.org/git/glibc.git
Update.
2003-04-28 Ulrich Drepper <drepper@redhat.com> * nscd/nscd_getgr_r.c: Compact code a bit. Add some __builtin_expect. * nscd/nscd_getpw_r.c: Likewise. * nscd/nscd_gethst_r.c: Likewise.
This commit is contained in:
parent
fe45381231
commit
12c8051397
|
@ -1,3 +1,9 @@
|
||||||
|
2003-04-28 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* nscd/nscd_getgr_r.c: Compact code a bit. Add some __builtin_expect.
|
||||||
|
* nscd/nscd_getpw_r.c: Likewise.
|
||||||
|
* nscd/nscd_gethst_r.c: Likewise.
|
||||||
|
|
||||||
2003-04-27 Ulrich Drepper <drepper@redhat.com>
|
2003-04-27 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
* nscd/pwdcache.c: Initialize .version element in result.
|
* nscd/pwdcache.c: Initialize .version element in result.
|
||||||
|
|
|
@ -70,6 +70,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
|
||||||
gr_response_header gr_resp;
|
gr_response_header gr_resp;
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
struct iovec vec[2];
|
struct iovec vec[2];
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
if (sock == -1)
|
if (sock == -1)
|
||||||
{
|
{
|
||||||
|
@ -88,25 +89,18 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
|
nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
|
||||||
if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
|
if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__read (sock, &gr_resp,
|
nbytes = TEMP_FAILURE_RETRY (__read (sock, &gr_resp,
|
||||||
sizeof (gr_response_header)));
|
sizeof (gr_response_header)));
|
||||||
if (nbytes != (ssize_t) sizeof (gr_response_header))
|
if (nbytes != (ssize_t) sizeof (gr_response_header))
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gr_resp.found == -1)
|
if (gr_resp.found == -1)
|
||||||
{
|
{
|
||||||
/* The daemon does not cache this database. */
|
/* The daemon does not cache this database. */
|
||||||
__close (sock);
|
|
||||||
__nss_not_use_nscd_group = 1;
|
__nss_not_use_nscd_group = 1;
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gr_resp.found == 1)
|
if (gr_resp.found == 1)
|
||||||
|
@ -123,12 +117,12 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
|
||||||
& (__alignof__ (char *) - 1));
|
& (__alignof__ (char *) - 1));
|
||||||
total_len = align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *)
|
total_len = align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *)
|
||||||
+ gr_resp.gr_name_len + gr_resp.gr_passwd_len;
|
+ gr_resp.gr_name_len + gr_resp.gr_passwd_len;
|
||||||
if (buflen < total_len)
|
if (__builtin_expect (buflen < total_len, 0))
|
||||||
{
|
{
|
||||||
no_room:
|
no_room:
|
||||||
__set_errno (ERANGE);
|
__set_errno (ERANGE);
|
||||||
__close (sock);
|
result = ERANGE;
|
||||||
return ERANGE;
|
goto out;
|
||||||
}
|
}
|
||||||
buflen -= total_len;
|
buflen -= total_len;
|
||||||
|
|
||||||
|
@ -156,11 +150,9 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
|
||||||
total_len += gr_resp.gr_name_len + gr_resp.gr_passwd_len;
|
total_len += gr_resp.gr_name_len + gr_resp.gr_passwd_len;
|
||||||
|
|
||||||
/* Get this data. */
|
/* Get this data. */
|
||||||
if ((size_t) TEMP_FAILURE_RETRY (__readv (sock, vec, 2)) != total_len)
|
size_t n = TEMP_FAILURE_RETRY (__readv (sock, vec, 2));
|
||||||
{
|
if (__builtin_expect (n != total_len, 0))
|
||||||
__close (sock);
|
goto out;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear the terminating entry. */
|
/* Clear the terminating entry. */
|
||||||
resultbuf->gr_mem[gr_resp.gr_mem_cnt] = NULL;
|
resultbuf->gr_mem[gr_resp.gr_mem_cnt] = NULL;
|
||||||
|
@ -174,26 +166,28 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
|
||||||
p += len[cnt];
|
p += len[cnt];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total_len > buflen)
|
if (__builtin_expect (total_len > buflen, 0))
|
||||||
goto no_room;
|
goto no_room;
|
||||||
|
|
||||||
if ((size_t) TEMP_FAILURE_RETRY (__read (sock, resultbuf->gr_mem[0],
|
result = 0;
|
||||||
total_len)) != total_len)
|
n = TEMP_FAILURE_RETRY (__read (sock, resultbuf->gr_mem[0],
|
||||||
|
total_len));
|
||||||
|
if (__builtin_expect (n != total_len, 0))
|
||||||
{
|
{
|
||||||
__close (sock);
|
|
||||||
/* The `errno' to some value != ERANGE. */
|
/* The `errno' to some value != ERANGE. */
|
||||||
__set_errno (ENOENT);
|
__set_errno (ENOENT);
|
||||||
return ENOENT;
|
result = ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
__close (sock);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
__close (sock);
|
|
||||||
/* The `errno' to some value != ERANGE. */
|
/* The `errno' to some value != ERANGE. */
|
||||||
__set_errno (ENOENT);
|
__set_errno (ENOENT);
|
||||||
return ENOENT;
|
result = ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
__close (sock);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
||||||
request_header req;
|
request_header req;
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
struct iovec vec[4];
|
struct iovec vec[4];
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
if (sock == -1)
|
if (sock == -1)
|
||||||
{
|
{
|
||||||
|
@ -142,25 +143,18 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
|
nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
|
||||||
if ((size_t) nbytes != sizeof (request_header) + req.key_len)
|
if ((size_t) nbytes != sizeof (request_header) + req.key_len)
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__read (sock, &hst_resp,
|
nbytes = TEMP_FAILURE_RETRY (__read (sock, &hst_resp,
|
||||||
sizeof (hst_response_header)));
|
sizeof (hst_response_header)));
|
||||||
if (nbytes != sizeof (hst_response_header))
|
if (__builtin_expect (nbytes != sizeof (hst_response_header), 0))
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hst_resp.found == -1)
|
if (hst_resp.found == -1)
|
||||||
{
|
{
|
||||||
/* The daemon does not cache this database. */
|
/* The daemon does not cache this database. */
|
||||||
__close (sock);
|
|
||||||
__nss_not_use_nscd_hosts = 1;
|
__nss_not_use_nscd_hosts = 1;
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hst_resp.found == 1)
|
if (hst_resp.found == 1)
|
||||||
|
@ -190,8 +184,8 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
||||||
{
|
{
|
||||||
no_room:
|
no_room:
|
||||||
__set_errno (ERANGE);
|
__set_errno (ERANGE);
|
||||||
__close (sock);
|
result = ERANGE;
|
||||||
return ERANGE;
|
goto out;
|
||||||
}
|
}
|
||||||
cp += align1;
|
cp += align1;
|
||||||
|
|
||||||
|
@ -264,10 +258,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
||||||
resultbuf->h_addr_list[cnt] = NULL;
|
resultbuf->h_addr_list[cnt] = NULL;
|
||||||
|
|
||||||
if ((size_t) TEMP_FAILURE_RETRY (__readv (sock, vec, n)) != total_len)
|
if ((size_t) TEMP_FAILURE_RETRY (__readv (sock, vec, n)) != total_len)
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now we also can read the aliases. */
|
/* Now we also can read the aliases. */
|
||||||
total_len = 0;
|
total_len = 0;
|
||||||
|
@ -285,23 +276,21 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
||||||
|
|
||||||
/* And finally read the aliases. */
|
/* And finally read the aliases. */
|
||||||
if ((size_t) TEMP_FAILURE_RETRY (__read (sock, resultbuf->h_aliases[0],
|
if ((size_t) TEMP_FAILURE_RETRY (__read (sock, resultbuf->h_aliases[0],
|
||||||
total_len)) != total_len)
|
total_len)) == total_len)
|
||||||
{
|
result = 0;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
__close (sock);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Store the error number. */
|
/* Store the error number. */
|
||||||
*h_errnop = hst_resp.error;
|
*h_errnop = hst_resp.error;
|
||||||
|
|
||||||
__close (sock);
|
|
||||||
/* The `errno' to some value != ERANGE. */
|
/* The `errno' to some value != ERANGE. */
|
||||||
__set_errno (ENOENT);
|
__set_errno (ENOENT);
|
||||||
return ENOENT;
|
result = ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
__close (sock);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
|
||||||
pw_response_header pw_resp;
|
pw_response_header pw_resp;
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
struct iovec vec[2];
|
struct iovec vec[2];
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
if (sock == -1)
|
if (sock == -1)
|
||||||
{
|
{
|
||||||
|
@ -89,25 +90,18 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
|
nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
|
||||||
if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
|
if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__read (sock, &pw_resp,
|
nbytes = TEMP_FAILURE_RETRY (__read (sock, &pw_resp,
|
||||||
sizeof (pw_response_header)));
|
sizeof (pw_response_header)));
|
||||||
if (nbytes != (ssize_t) sizeof (pw_response_header))
|
if (nbytes != (ssize_t) sizeof (pw_response_header))
|
||||||
{
|
goto out;
|
||||||
__close (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pw_resp.found == -1)
|
if (__builtin_expect (pw_resp.found == -1, 0))
|
||||||
{
|
{
|
||||||
/* The daemon does not cache this database. */
|
/* The daemon does not cache this database. */
|
||||||
__close (sock);
|
|
||||||
__nss_not_use_nscd_passwd = 1;
|
__nss_not_use_nscd_passwd = 1;
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw_resp.found == 1)
|
if (pw_resp.found == 1)
|
||||||
|
@ -117,11 +111,11 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
|
||||||
+ pw_resp.pw_gecos_len + pw_resp.pw_dir_len
|
+ pw_resp.pw_gecos_len + pw_resp.pw_dir_len
|
||||||
+ pw_resp.pw_shell_len);
|
+ pw_resp.pw_shell_len);
|
||||||
|
|
||||||
if (buflen < total)
|
if (__builtin_expect (buflen < total, 0))
|
||||||
{
|
{
|
||||||
__set_errno (ERANGE);
|
__set_errno (ERANGE);
|
||||||
__close (sock);
|
result = ERANGE;
|
||||||
return ERANGE;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the information we already have. */
|
/* Set the information we already have. */
|
||||||
|
@ -145,15 +139,18 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
|
||||||
|
|
||||||
nbytes = TEMP_FAILURE_RETRY (__read (sock, buffer, total));
|
nbytes = TEMP_FAILURE_RETRY (__read (sock, buffer, total));
|
||||||
|
|
||||||
__close (sock);
|
if (nbytes == (ssize_t) total)
|
||||||
|
result = 0;
|
||||||
return nbytes == (ssize_t) total ? 0 : -1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
__close (sock);
|
|
||||||
/* The `errno' to some value != ERANGE. */
|
/* The `errno' to some value != ERANGE. */
|
||||||
__set_errno (ENOENT);
|
__set_errno (ENOENT);
|
||||||
return ENOENT;
|
result = ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
__close (sock);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue