summaryrefslogtreecommitdiff
path: root/nscd
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2013-05-26 16:21:10 +0200
committerThomas Schwinge <thomas@codesourcery.com>2013-05-26 16:21:10 +0200
commitd9e11d0c51182483d30760f3c66000a0e9b8c922 (patch)
treee1d147b2d9d270f8cec60e499bc5fd738144d4c2 /nscd
parentd5ce2d1c5dfae01688cad679b2fbd071e70a1f3a (diff)
parent9a079e270a9bec7e1fe28aeda63e07c1bb808d44 (diff)
Merge branch 'baseline' into refs/top-bases/tschwinge/Roger_Whittaker
Conflicts: sysdeps/mach/hurd/i386/init-first.c
Diffstat (limited to 'nscd')
-rw-r--r--nscd/connections.c1
-rw-r--r--nscd/grpcache.c40
-rw-r--r--nscd/hstcache.c1
-rw-r--r--nscd/initgrcache.c36
-rw-r--r--nscd/nscd.c9
-rw-r--r--nscd/nscd_gethst_r.c1
-rw-r--r--nscd/nscd_getserv_r.c1
-rw-r--r--nscd/nscd_helper.c1
-rw-r--r--nscd/pwdcache.c40
-rw-r--r--nscd/servicescache.c38
10 files changed, 97 insertions, 71 deletions
diff --git a/nscd/connections.c b/nscd/connections.c
index 56c327971b..7099215916 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stdint.h>
#include <arpa/inet.h>
#ifdef HAVE_NETLINK
# include <linux/netlink.h>
diff --git a/nscd/grpcache.c b/nscd/grpcache.c
index d25d8e92f2..5658792445 100644
--- a/nscd/grpcache.c
+++ b/nscd/grpcache.c
@@ -75,8 +75,8 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
const void *key, struct group *grp, uid_t owner,
struct hashentry *const he, struct datahead *dh, int errval)
{
+ bool all_written = true;
ssize_t total;
- ssize_t written;
time_t t = time (NULL);
/* We allocate all data in one memory block: the iov vector,
@@ -105,7 +105,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
/* Reload with the same time-to-live value. */
timeout = dh->timeout = t + db->postimeout;
- written = total = 0;
+ total = 0;
}
else
{
@@ -113,11 +113,10 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
case. */
total = sizeof (notfound);
- if (fd != -1)
- written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
- MSG_NOSIGNAL));
- else
- written = total;
+ if (fd != -1
+ && TEMP_FAILURE_RETRY (send (fd, &notfound, total,
+ MSG_NOSIGNAL)) != total)
+ all_written = false;
/* If we have a transient error or cannot permanently store
the result, so be it. */
@@ -197,9 +196,9 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
gr_mem_len_total += gr_mem_len[gr_mem_cnt];
}
- written = total = (offsetof (struct dataset, strdata)
- + gr_mem_cnt * sizeof (uint32_t)
- + gr_name_len + gr_passwd_len + gr_mem_len_total);
+ total = (offsetof (struct dataset, strdata)
+ + gr_mem_cnt * sizeof (uint32_t)
+ + gr_name_len + gr_passwd_len + gr_mem_len_total);
/* If we refill the cache, first assume the reconrd did not
change. Allocate memory on the cache since it is likely
@@ -328,20 +327,27 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
<= (sizeof (struct database_pers_head)
+ db->head->module * sizeof (ref_t)
+ db->head->data_size));
- written = sendfileall (fd, db->wr_fd,
- (char *) &dataset->resp
- - (char *) db->head, dataset->head.recsize);
+ ssize_t written = sendfileall (fd, db->wr_fd,
+ (char *) &dataset->resp
+ - (char *) db->head,
+ dataset->head.recsize);
+ if (written != dataset->head.recsize)
+ {
# ifndef __ASSUME_SENDFILE
- if (written == -1 && errno == ENOSYS)
- goto use_write;
+ if (written == -1 && errno == ENOSYS)
+ goto use_write;
# endif
+ all_written = false;
+ }
}
else
# ifndef __ASSUME_SENDFILE
use_write:
# endif
#endif
- written = writeall (fd, &dataset->resp, dataset->head.recsize);
+ if (writeall (fd, &dataset->resp, dataset->head.recsize)
+ != dataset->head.recsize)
+ all_written = false;
}
/* Add the record to the database. But only if it has not been
@@ -401,7 +407,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
}
}
- if (__builtin_expect (written != total, 0) && debug_level > 0)
+ if (__builtin_expect (!all_written, 0) && debug_level > 0)
{
char buf[256];
dbg_log (_("short write in %s: %s"), __FUNCTION__,
diff --git a/nscd/hstcache.c b/nscd/hstcache.c
index ca2145212d..0d421fcbbb 100644
--- a/nscd/hstcache.c
+++ b/nscd/hstcache.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <stdint.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <sys/mman.h>
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index 196407c870..462780e624 100644
--- a/nscd/initgrcache.c
+++ b/nscd/initgrcache.c
@@ -171,15 +171,16 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
nip = nip->next;
}
+ bool all_written;
ssize_t total;
- ssize_t written;
time_t timeout;
out:
+ all_written = true;
timeout = MAX_TIMEOUT_VALUE;
if (!any_success)
{
/* Nothing found. Create a negative result record. */
- written = total = sizeof (notfound);
+ total = sizeof (notfound);
if (he != NULL && all_tryagain)
{
@@ -197,9 +198,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
{
/* We have no data. This means we send the standard reply for this
case. */
- if (fd != -1)
- written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
- MSG_NOSIGNAL));
+ if (fd != -1
+ && TEMP_FAILURE_RETRY (send (fd, &notfound, total,
+ MSG_NOSIGNAL)) != total)
+ all_written = false;
/* If we have a transient error or cannot permanently store
the result, so be it. */
@@ -251,8 +253,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
else
{
- written = total = (offsetof (struct dataset, strdata)
- + start * sizeof (int32_t));
+ total = offsetof (struct dataset, strdata) + start * sizeof (int32_t);
/* If we refill the cache, first assume the reconrd did not
change. Allocate memory on the cache since it is likely
@@ -365,20 +366,27 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
<= (sizeof (struct database_pers_head)
+ db->head->module * sizeof (ref_t)
+ db->head->data_size));
- written = sendfileall (fd, db->wr_fd,
- (char *) &dataset->resp
- - (char *) db->head, dataset->head.recsize);
+ ssize_t written = sendfileall (fd, db->wr_fd,
+ (char *) &dataset->resp
+ - (char *) db->head,
+ dataset->head.recsize);
+ if (written != dataset->head.recsize)
+ {
# ifndef __ASSUME_SENDFILE
- if (written == -1 && errno == ENOSYS)
- goto use_write;
+ if (written == -1 && errno == ENOSYS)
+ goto use_write;
# endif
+ all_written = false;
+ }
}
else
# ifndef __ASSUME_SENDFILE
use_write:
# endif
#endif
- written = writeall (fd, &dataset->resp, dataset->head.recsize);
+ if (writeall (fd, &dataset->resp, dataset->head.recsize)
+ != dataset->head.recsize)
+ all_written = false;
}
@@ -405,7 +413,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
free (groups);
- if (__builtin_expect (written != total, 0) && debug_level > 0)
+ if (__builtin_expect (!all_written, 0) && debug_level > 0)
{
char buf[256];
dbg_log (_("short write in %s: %s"), __FUNCTION__,
diff --git a/nscd/nscd.c b/nscd/nscd.c
index 26cf3c2692..ffbc6f8bc9 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -252,15 +252,6 @@ main (int argc, char **argv)
for (i = min_close_fd; i < getdtablesize (); i++)
close (i);
- if (run_mode == RUN_DAEMONIZE)
- {
- pid = fork ();
- if (pid == -1)
- error (EXIT_FAILURE, errno, _("cannot fork"));
- if (pid != 0)
- exit (0);
- }
-
setsid ();
if (chdir ("/") != 0)
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c
index 4ede24b194..e07f62236a 100644
--- a/nscd/nscd_gethst_r.c
+++ b/nscd/nscd_gethst_r.c
@@ -20,6 +20,7 @@
#include <resolv.h>
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
#include <arpa/nameser.h>
#include <not-cancel.h>
diff --git a/nscd/nscd_getserv_r.c b/nscd/nscd_getserv_r.c
index f79bd42e1a..c9c890c63c 100644
--- a/nscd/nscd_getserv_r.c
+++ b/nscd/nscd_getserv_r.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <not-cancel.h>
#include <_itoa.h>
+#include <stdint.h>
#include "nscd-client.h"
#include "nscd_proto.h"
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index ba58893560..8587e4549c 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <stdint.h>
#include <sys/mman.h>
#include <sys/poll.h>
#include <sys/socket.h>
diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c
index ef492b58c1..4f3fb416da 100644
--- a/nscd/pwdcache.c
+++ b/nscd/pwdcache.c
@@ -81,8 +81,8 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
const void *key, struct passwd *pwd, uid_t owner,
struct hashentry *const he, struct datahead *dh, int errval)
{
+ bool all_written = true;
ssize_t total;
- ssize_t written;
time_t t = time (NULL);
/* We allocate all data in one memory block: the iov vector,
@@ -111,17 +111,18 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
/* Reload with the same time-to-live value. */
timeout = dh->timeout = t + db->postimeout;
- written = total = 0;
+ total = 0;
}
else
{
/* We have no data. This means we send the standard reply for this
case. */
- written = total = sizeof (notfound);
+ total = sizeof (notfound);
- if (fd != -1)
- written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
- MSG_NOSIGNAL));
+ if (fd != -1
+ && TEMP_FAILURE_RETRY (send (fd, &notfound, total,
+ MSG_NOSIGNAL)) != total)
+ all_written = false;
/* If we have a transient error or cannot permanently store
the result, so be it. */
@@ -189,9 +190,9 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
n = snprintf (buf, buf_len, "%d%c%n%s", pwd->pw_uid, '\0',
&key_offset, (char *) key) + 1;
- written = total = (offsetof (struct dataset, strdata)
- + pw_name_len + pw_passwd_len
- + pw_gecos_len + pw_dir_len + pw_shell_len);
+ total = (offsetof (struct dataset, strdata)
+ + pw_name_len + pw_passwd_len
+ + pw_gecos_len + pw_dir_len + pw_shell_len);
/* If we refill the cache, first assume the reconrd did not
change. Allocate memory on the cache since it is likely
@@ -304,20 +305,27 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
<= (sizeof (struct database_pers_head)
+ db->head->module * sizeof (ref_t)
+ db->head->data_size));
- written = sendfileall (fd, db->wr_fd,
- (char *) &dataset->resp
- - (char *) db->head, dataset->head.recsize );
+ ssize_t written = sendfileall (fd, db->wr_fd,
+ (char *) &dataset->resp
+ - (char *) db->head,
+ dataset->head.recsize);
+ if (written != dataset->head.recsize)
+ {
# ifndef __ASSUME_SENDFILE
- if (written == -1 && errno == ENOSYS)
- goto use_write;
+ if (written == -1 && errno == ENOSYS)
+ goto use_write;
# endif
+ all_written = false;
+ }
}
else
# ifndef __ASSUME_SENDFILE
use_write:
# endif
#endif
- written = writeall (fd, &dataset->resp, dataset->head.recsize);
+ if (writeall (fd, &dataset->resp, dataset->head.recsize)
+ != dataset->head.recsize)
+ all_written = false;
}
@@ -377,7 +385,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
}
}
- if (__builtin_expect (written != total, 0) && debug_level > 0)
+ if (__builtin_expect (!all_written, 0) && debug_level > 0)
{
char buf[256];
dbg_log (_("short write in %s: %s"), __FUNCTION__,
diff --git a/nscd/servicescache.c b/nscd/servicescache.c
index d29cde7d63..b7738a7cb4 100644
--- a/nscd/servicescache.c
+++ b/nscd/servicescache.c
@@ -22,6 +22,7 @@
#include <libintl.h>
#include <netdb.h>
#include <unistd.h>
+#include <stdint.h>
#include <sys/mman.h>
#include <kernel-features.h>
@@ -65,8 +66,8 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
const void *key, struct servent *serv, uid_t owner,
struct hashentry *const he, struct datahead *dh, int errval)
{
+ bool all_written = true;
ssize_t total;
- ssize_t written;
time_t t = time (NULL);
/* We allocate all data in one memory block: the iov vector,
@@ -95,17 +96,18 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
/* Reload with the same time-to-live value. */
timeout = dh->timeout = t + db->postimeout;
- written = total = 0;
+ total = 0;
}
else
{
/* We have no data. This means we send the standard reply for this
case. */
- written = total = sizeof (notfound);
+ total = sizeof (notfound);
- if (fd != -1)
- written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
- MSG_NOSIGNAL));
+ if (fd != -1
+ && TEMP_FAILURE_RETRY (send (fd, &notfound, total,
+ MSG_NOSIGNAL)) != total)
+ all_written = false;
/* If we have a transient error or cannot permanently store
the result, so be it. */
@@ -182,7 +184,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
+ s_name_len
+ s_proto_len
+ s_aliases_cnt * sizeof (uint32_t));
- written = total;
/* If we refill the cache, first assume the reconrd did not
change. Allocate memory on the cache since it is likely
@@ -290,25 +291,32 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
{
assert (db->wr_fd != -1);
assert ((char *) &dataset->resp > (char *) db->data);
- assert ((char *) &dataset->resp - (char *) db->head
+ assert ((char *) dataset - (char *) db->head
+ total
<= (sizeof (struct database_pers_head)
+ db->head->module * sizeof (ref_t)
+ db->head->data_size));
- written = sendfileall (fd, db->wr_fd,
- (char *) &dataset->resp
- - (char *) db->head, total);
+ ssize_t written = sendfileall (fd, db->wr_fd,
+ (char *) &dataset->resp
+ - (char *) db->head,
+ dataset->head.recsize);
+ if (written != dataset->head.recsize)
+ {
# ifndef __ASSUME_SENDFILE
- if (written == -1 && errno == ENOSYS)
- goto use_write;
+ if (written == -1 && errno == ENOSYS)
+ goto use_write;
# endif
+ all_written = false;
+ }
}
else
# ifndef __ASSUME_SENDFILE
use_write:
# endif
#endif
- written = writeall (fd, &dataset->resp, total);
+ if (writeall (fd, &dataset->resp, dataset->head.recsize)
+ != dataset->head.recsize)
+ all_written = false;
}
/* Add the record to the database. But only if it has not been
@@ -332,7 +340,7 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
}
}
- if (__builtin_expect (written != total, 0) && debug_level > 0)
+ if (__builtin_expect (!all_written, 0) && debug_level > 0)
{
char buf[256];
dbg_log (_("short write in %s: %s"), __FUNCTION__,