summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-02-25 15:40:21 +0100
committerHans de Goede <hdegoede@redhat.com>2013-03-06 16:22:15 +0100
commitf45a4c0ae527cecd9a261444569b21d1c8de00ad (patch)
tree8678130bd009ffd4084b626544f169dfdee76b7a
parent260cde2c88e0c25601953690b0814d141a637b63 (diff)
downloadvd_agent-f45a4c0ae527cecd9a261444569b21d1c8de00ad.tar.gz
vd_agent-f45a4c0ae527cecd9a261444569b21d1c8de00ad.tar.xz
vd_agent-f45a4c0ae527cecd9a261444569b21d1c8de00ad.zip
file-xfers: Handle writing errors
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--src/vdagent-file-xfers.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/vdagent-file-xfers.c b/src/vdagent-file-xfers.c
index faff743..959a491 100644
--- a/src/vdagent-file-xfers.c
+++ b/src/vdagent-file-xfers.c
@@ -262,26 +262,28 @@ void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
return;
len = write(task->file_fd, msg->data, msg->size);
- if (len == -1) {
+ if (len == msg->size) {
+ task->read_bytes += msg->size;
+ if (task->read_bytes >= task->file_size) {
+ if (task->read_bytes == task->file_size) {
+ if (xfers->debug)
+ syslog(LOG_DEBUG, "file-xfer: task %u %s has completed",
+ task->id, task->file_name);
+ close(task->file_fd);
+ task->file_fd = -1;
+ status = VD_AGENT_FILE_XFER_STATUS_SUCCESS;
+ } else {
+ syslog(LOG_ERR, "file-xfer: error received too much data");
+ status = VD_AGENT_FILE_XFER_STATUS_ERROR;
+ }
+ }
+ } else {
syslog(LOG_ERR, "file-xfer: error writing %s: %s", task->file_name,
strerror(errno));
- /* TODO: close, cancel dnd */
- return ;
+ status = VD_AGENT_FILE_XFER_STATUS_ERROR;
}
- task->read_bytes += msg->size;
- if (task->read_bytes >= task->file_size) {
- if (task->read_bytes == task->file_size) {
- if (xfers->debug)
- syslog(LOG_DEBUG, "file-xfer: task %u %s has completed",
- task->id, task->file_name);
- close(task->file_fd);
- task->file_fd = -1;
- status = VD_AGENT_FILE_XFER_STATUS_SUCCESS;
- } else {
- syslog(LOG_ERR, "file-xfer: error received too much data");
- status = VD_AGENT_FILE_XFER_STATUS_ERROR;
- }
+ if (status != -1) {
udscs_write(xfers->vdagentd, VDAGENTD_FILE_XFER_STATUS,
msg->id, status, NULL, 0);
g_hash_table_remove(xfers->xfers, GUINT_TO_POINTER(msg->id));