-/* Copyright (C) 1998-2012 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
+#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <stdint.h>
#include <sys/mman.h>
+#include <sys/param.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <not-cancel.h>
-#include <nis/rpcsvc/nis.h>
#include <kernel-features.h>
+#include <nss.h>
#include "nscd-client.h"
-
/* Extra time we wait if the socket is still receiving data. This
value is in milliseconds. Note that the other side is nscd on the
local machine and it is already transmitting data. So the wait
ssize_t ret = TEMP_FAILURE_RETRY (__readv (fd, iov, iovcnt));
if (ret <= 0)
{
- if (__builtin_expect (ret == 0 || errno != EAGAIN, 1))
+ if (__glibc_likely (ret == 0 || errno != EAGAIN))
/* A genuine error or no data to read. */
return ret;
{
int sock;
-#ifdef SOCK_CLOEXEC
-# ifndef __ASSUME_SOCK_CLOEXEC
- if (__have_sock_cloexec >= 0)
-# endif
- {
- sock = __socket (PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
-# ifndef __ASSUME_SOCK_CLOEXEC
- if (__have_sock_cloexec == 0)
- __have_sock_cloexec = sock != -1 || errno != EINVAL ? 1 : -1;
-# endif
- }
-#endif
-#ifndef __ASSUME_SOCK_CLOEXEC
-# ifdef SOCK_CLOEXEC
- if (__have_sock_cloexec < 0)
-# endif
- sock = __socket (PF_UNIX, SOCK_STREAM, 0);
-#endif
+ sock = __socket (PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (sock < 0)
return -1;
+ size_t real_sizeof_reqdata = sizeof (request_header) + keylen;
struct
{
request_header req;
- char key[keylen];
- } reqdata;
- size_t real_sizeof_reqdata = sizeof (request_header) + keylen;
-
-#ifndef __ASSUME_SOCK_CLOEXEC
-# ifdef SOCK_NONBLOCK
- if (__have_sock_cloexec < 0)
-# endif
- /* Make socket non-blocking. */
- __fcntl (sock, F_SETFL, O_RDWR | O_NONBLOCK);
-#endif
+ char key[];
+ } *reqdata = alloca (real_sizeof_reqdata);
struct sockaddr_un sun;
sun.sun_family = AF_UNIX;
&& errno != EINPROGRESS)
goto out;
- reqdata.req.version = NSCD_VERSION;
- reqdata.req.type = type;
- reqdata.req.key_len = keylen;
+ reqdata->req.version = NSCD_VERSION;
+ reqdata->req.type = type;
+ reqdata->req.key_len = keylen;
- memcpy (reqdata.key, key, keylen);
+ memcpy (reqdata->key, key, keylen);
bool first_try = true;
struct timeval tvend;
#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
#endif
- ssize_t wres = TEMP_FAILURE_RETRY (__send (sock, &reqdata,
+ ssize_t wres = TEMP_FAILURE_RETRY (__send (sock, reqdata,
real_sizeof_reqdata,
MSG_NOSIGNAL));
- if (__builtin_expect (wres == (ssize_t) real_sizeof_reqdata, 1))
+ if (__glibc_likely (wres == (ssize_t) real_sizeof_reqdata))
/* We managed to send the request. */
return sock;
}
out:
- close_not_cancel_no_status (sock);
+ __close_nocancel_nostatus (sock);
return -1;
}
int *ip = (void *) CMSG_DATA (cmsg);
mapfd = *ip;
- if (__builtin_expect (n != keylen && n != keylen + sizeof (mapsize), 0))
+ if (__glibc_unlikely (n != keylen && n != keylen + sizeof (mapsize)))
goto out_close;
- if (__builtin_expect (strcmp (resdata, key) != 0, 0))
+ if (__glibc_unlikely (strcmp (resdata, key) != 0))
goto out_close;
- if (__builtin_expect (n == keylen, 0))
+ if (__glibc_unlikely (n == keylen))
{
struct stat64 st;
if (__builtin_expect (fstat64 (mapfd, &st) != 0, 0)
/* The file is large enough, map it now. */
void *mapping = __mmap (NULL, mapsize, PROT_READ, MAP_SHARED, mapfd, 0);
- if (__builtin_expect (mapping != MAP_FAILED, 1))
+ if (__glibc_likely (mapping != MAP_FAILED))
{
/* Check whether the database is correct and up-to-date. */
struct database_pers_head *head = mapping;
ALIGN)
+ head->data_size);
- if (__builtin_expect (mapsize < size, 0))
+ if (__glibc_unlikely (mapsize < size))
goto out_unmap;
/* Allocate a record for the mapping. */
cur = mapptr->mapped;
- if (__builtin_expect (cur != NO_MAPPING, 1))
+ if (__glibc_likely (cur != NO_MAPPING))
{
/* If not mapped or timestamp not updated, request new map. */
if (cur == NULL
cur = __nscd_get_mapping (type, name,
(struct mapped_database **) &mapptr->mapped);
- if (__builtin_expect (cur != NO_MAPPING, 1))
+ if (__glibc_likely (cur != NO_MAPPING))
{
if (__builtin_expect (((*gc_cyclep = cur->head->gc_cycle) & 1) != 0,
0))
#define MINIMUM_HASHENTRY_SIZE \
(offsetof (struct hashentry, dellist) + sizeof (int32_t))
-
/* Don't return const struct datahead *, as eventhough the record
is normally constant, it can change arbitrarily during nscd
garbage collection. */
__nscd_cache_search (request_type type, const char *key, size_t keylen,
const struct mapped_database *mapped, size_t datalen)
{
- unsigned long int hash = __nis_hash (key, keylen) % mapped->head->module;
+ unsigned long int hash = __nss_hash (key, keylen) % mapped->head->module;
size_t datasize = mapped->datasize;
ref_t trail = mapped->head->array[hash];
struct hashentry *here = (struct hashentry *) (mapped->data + work);
ref_t here_key, here_packet;
-#ifndef _STRING_ARCH_unaligned
+#if !_STRING_ARCH_unaligned
/* Although during garbage collection when moving struct hashentry
records around we first copy from old to new location and then
adjust pointer from previous hashentry to it, there is no barrier
struct datahead *dh
= (struct datahead *) (mapped->data + here_packet);
-#ifndef _STRING_ARCH_unaligned
+#if !_STRING_ARCH_unaligned
if ((uintptr_t) dh & (__alignof__ (*dh) - 1))
return NULL;
#endif
struct hashentry *trailelem;
trailelem = (struct hashentry *) (mapped->data + trail);
-#ifndef _STRING_ARCH_unaligned
+#if !_STRING_ARCH_unaligned
/* We have to redo the checks. Maybe the data changed. */
if ((uintptr_t) trailelem & (__alignof__ (*trailelem) - 1))
return NULL;
return sock;
}
- close_not_cancel_no_status (sock);
+ __close_nocancel_nostatus (sock);
}
__set_errno (saved_errno);