From c85ae56edc982d28df5cb29eedcd9d8bc9840a05 Mon Sep 17 00:00:00 2001 From: shenlongxing Date: Mon, 4 Jun 2018 23:59:21 +0800 Subject: [PATCH] Fix write() errno error --- src/cluster.c | 2 +- src/redis-cli.c | 2 +- src/replication.c | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 0635d7c07..f457280b8 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -2120,7 +2120,7 @@ void clusterWriteHandler(aeEventLoop *el, int fd, void *privdata, int mask) { nwritten = write(fd, link->sndbuf, sdslen(link->sndbuf)); if (nwritten <= 0) { serverLog(LL_DEBUG,"I/O error writing to node link: %s", - strerror(errno)); + (nwritten == -1) ? strerror(errno) : "short write"); handleLinkIOError(link); return; } diff --git a/src/redis-cli.c b/src/redis-cli.c index 05865a925..0ee9f84ed 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -5575,7 +5575,7 @@ static void getRDB(void) { nwritten = write(fd, buf, nread); if (nwritten != nread) { fprintf(stderr,"Error writing data to file: %s\n", - strerror(errno)); + (nwritten == -1) ? strerror(errno) : "short write"); exit(1); } payload -= nread; diff --git a/src/replication.c b/src/replication.c index 8c01bfb51..0b7d57910 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1105,7 +1105,7 @@ void restartAOF() { #define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { char buf[4096]; - ssize_t nread, readlen; + ssize_t nread, readlen, nwritten; off_t left; UNUSED(el); UNUSED(privdata); @@ -1206,8 +1206,9 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { } server.repl_transfer_lastio = server.unixtime; - if (write(server.repl_transfer_fd,buf,nread) != nread) { - serverLog(LL_WARNING,"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchronization: %s", strerror(errno)); + if ((nwritten = write(server.repl_transfer_fd,buf,nread)) != nread) { + serverLog(LL_WARNING,"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchronization: %s", + (nwritten == -1) ? strerror(errno) : "short write"); goto error; } server.repl_transfer_read += nread;