summaryrefslogtreecommitdiff
path: root/nscd/grpcache.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2012-12-04 16:14:13 +0100
committerAndreas Schwab <schwab@suse.de>2013-04-15 10:33:52 +0200
commit306dfba9e1daac21ab5a45256b367aea9cf9c3ee (patch)
tree733e50d1d866af426cab811c4527733bc1eb4eeb /nscd/grpcache.c
parent206a6699116215c591c8562c67106f7e17146608 (diff)
Properly check for short writes when sending the response in nscd
Diffstat (limited to 'nscd/grpcache.c')
-rw-r--r--nscd/grpcache.c40
1 files changed, 23 insertions, 17 deletions
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__,