summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-09-27 15:41:47 -0400
committerNathan Straz <nstraz@redhat.com>2013-10-02 14:11:33 -0400
commit06c18e4fd532d9f0b8b4b0196949fb60279e2c27 (patch)
tree3595f501e0b738f75cdb611f34262f9ad89f7384
parente5d68f8cfdc444791b28cb7b885a07cf62093c76 (diff)
downloadqarsh-06c18e4fd532d9f0b8b4b0196949fb60279e2c27.zip
qarsh-06c18e4fd532d9f0b8b4b0196949fb60279e2c27.tar.gz
qarsh-06c18e4fd532d9f0b8b4b0196949fb60279e2c27.tar.xz
Handle short writes during qacp receive
-rw-r--r--qacp.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/qacp.c b/qacp.c
index 39fffba..f441e07 100644
--- a/qacp.c
+++ b/qacp.c
@@ -259,7 +259,7 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
struct qa_packet *qp;
struct qa_packet *rp;
int outfd;
- ssize_t nwrote;
+ ssize_t ret, nwrote;
struct qp_rstat_pkt *rstatp;
int rstaterrno;
fd_set rfds;
@@ -317,20 +317,22 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
if (qp->qp_data.qp_count == 0) {
break;
}
- if ((nwrote = write(outfd, qp->qp_data.qp_blob, qp->qp_data.qp_count)) == -1) {
- fprintf(stderr, "write() error: %s\n", strerror(errno));
- rp = make_qp_returncode(-1, errno, strerror(errno));
- send_packet(qacp_fd, rp);
- qpfree(rp);
- break;
- } else if (nwrote == qp->qp_data.qp_count) {
- rp = make_qp_data_allow(0, nwrote);
- send_packet(qacp_fd, rp);
- qpfree(rp);
- } else {
- fprintf(stderr, "short write\n");
- break;
- }
+ nwrote = 0;
+ do {
+ ret = write(outfd, qp->qp_data.qp_blob, qp->qp_data.qp_count);
+ if (ret < 0) {
+ fprintf(stderr, "write() error: %s\n", strerror(errno));
+ rp = make_qp_returncode(-1, errno, strerror(errno));
+ send_packet(qacp_fd, rp);
+ qpfree(rp);
+ break;
+ }
+ nwrote += ret;
+ } while (nwrote < qp->qp_data.qp_count);
+
+ rp = make_qp_data_allow(0, nwrote);
+ send_packet(qacp_fd, rp);
+ qpfree(rp);
} else if (qp->qp_type == QP_RETURNCODE) {
if (qp->qp_returncode.qp_rc == 0) { /* success */
break;