diff --git a/appvm/copy_file.c b/appvm/copy_file.c index 5f7fc793..9e65c652 100644 --- a/appvm/copy_file.c +++ b/appvm/copy_file.c @@ -1,8 +1,10 @@ #include #include +#include "filecopy.h" + extern void notify_progress(int, int); -char * copy_file(int outfd, int infd, long long size) +int copy_file(int outfd, int infd, long long size) { char buf[4096]; long long written = 0; @@ -15,14 +17,24 @@ char * copy_file(int outfd, int infd, long long size) count = size - written; ret = read(infd, buf, count); if (!ret) - return("EOF while reading file"); + return COPY_FILE_READ_EOF; if (ret < 0) - return("error reading file"); + return COPY_FILE_READ_ERROR; if (!write_all(outfd, buf, ret)) - return("error writing file content"); + return COPY_FILE_WRITE_ERROR; notify_progress(ret, 0); written += ret; } - return NULL; + return COPY_FILE_OK; } +char * copy_file_status_to_str(int status) +{ + switch (status) { + case COPY_FILE_OK: return "OK"; + case COPY_FILE_READ_EOF: return "Unexpected end of data while reading"; + case COPY_FILE_READ_ERROR: return "Error reading"; + case COPY_FILE_WRITE_ERROR: return "Error writing"; + default: return "????????"; + } +} diff --git a/appvm/filecopy.h b/appvm/filecopy.h index b4f6638c..1fcd2d04 100644 --- a/appvm/filecopy.h +++ b/appvm/filecopy.h @@ -6,13 +6,21 @@ #define LEGAL_EOF 31415926 struct file_header { -unsigned int namelen; -unsigned int mode; -unsigned long long filelen; -unsigned int atime; -unsigned int atime_nsec; -unsigned int mtime; -unsigned int mtime_nsec; + unsigned int namelen; + unsigned int mode; + unsigned long long filelen; + unsigned int atime; + unsigned int atime_nsec; + unsigned int mtime; + unsigned int mtime_nsec; }; -char * copy_file(int outfd, int infd, long long size); +enum { + COPY_FILE_OK, + COPY_FILE_READ_EOF, + COPY_FILE_READ_ERROR, + COPY_FILE_WRITE_ERROR +}; + +int copy_file(int outfd, int infd, long long size); +char *copy_file_status_to_str(int status); diff --git a/appvm/qfile-agent.c b/appvm/qfile-agent.c index f7e27a98..e33b61c6 100644 --- a/appvm/qfile-agent.c +++ b/appvm/qfile-agent.c @@ -50,7 +50,7 @@ void write_headers(struct file_header *hdr, char *filename) { if (!write_all(1, hdr, sizeof(*hdr)) || !write_all(1, filename, hdr->namelen)) - gui_fatal("writing file headers to remove AppVM"); + exit(1); } int single_file_processor(char *filename, struct stat *st) @@ -67,15 +67,21 @@ int single_file_processor(char *filename, struct stat *st) hdr.mtime_nsec = st->st_mtim.tv_nsec; if (S_ISREG(mode)) { - char *ret; + int ret; fd = open(filename, O_RDONLY); if (!fd) gui_fatal("open %s", filename); hdr.filelen = st->st_size; write_headers(&hdr, filename); ret = copy_file(1, fd, hdr.filelen); - if (ret) - gui_fatal("Copying file %s: %s", filename, ret); + // if COPY_FILE_WRITE_ERROR, hopefully remote will produce a message + if (ret != COPY_FILE_OK) { + if (ret != COPY_FILE_WRITE_ERROR) + gui_fatal("Copying file %s: %s", filename, + copy_file_status_to_str(ret)); + else + exit(1); + } close(fd); } if (S_ISDIR(mode)) { @@ -89,7 +95,7 @@ int single_file_processor(char *filename, struct stat *st) hdr.filelen = st->st_size + 1; write_headers(&hdr, filename); if (!write_all(1, name, st->st_size + 1)) - gui_fatal("write to remote VM"); + exit(1); } return 0; } @@ -130,7 +136,7 @@ void send_vmname(char *vmname) memset(buf, 0, sizeof(buf)); strncat(buf, vmname, sizeof(buf) - 1); if (!write_all(1, buf, sizeof buf)) - gui_fatal("writing vmname to remote VM"); + exit(1); } char *get_item(char *data, char **current, int size) diff --git a/appvm/qvm-copy-to-vm2.kde b/appvm/qvm-copy-to-vm2.kde index 879279be..de28feec 100755 --- a/appvm/qvm-copy-to-vm2.kde +++ b/appvm/qvm-copy-to-vm2.kde @@ -43,6 +43,7 @@ done qdbus $REF close rm -f $PROGRESS_FILE -if ! [ "x"$agentstatus = xDONE ] ; then - kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details' -fi +# we do not want a dozen error messages, do we +# if ! [ "x"$agentstatus = xDONE ] ; then +# kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details' +# fi diff --git a/appvm/unpack.c b/appvm/unpack.c index ad53ebf5..eaa1744c 100644 --- a/appvm/unpack.c +++ b/appvm/unpack.c @@ -38,14 +38,19 @@ void fix_times_and_perms(struct file_header *hdr, char *name) void process_one_file_reg(struct file_header *hdr, char *name) { - char *ret; + int ret; int fdout = open(name, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, 0700); if (fdout < 0) do_exit(errno); ret = copy_file(fdout, 0, hdr->filelen); - if (ret) - do_exit(errno); + if (ret != COPY_FILE_OK) { + if (ret == COPY_FILE_READ_EOF + || ret == COPY_FILE_READ_ERROR) + do_exit(LEGAL_EOF); // hopefully remote will produce error message + else + do_exit(errno); + } close(fdout); fix_times_and_perms(hdr, name); } @@ -68,7 +73,7 @@ void process_one_file_link(struct file_header *hdr, char *name) if (hdr->filelen > MAX_PATH_LENGTH - 1) do_exit(ENAMETOOLONG); if (!read_all(0, content, hdr->filelen)) - do_exit(errno); + do_exit(LEGAL_EOF); // hopefully remote has produced error message content[hdr->filelen] = 0; if (symlink(content, name)) do_exit(errno); @@ -80,7 +85,7 @@ void process_one_file(struct file_header *hdr) if (hdr->namelen > MAX_PATH_LENGTH - 1) do_exit(ENAMETOOLONG); if (!read_all(0, namebuf, hdr->namelen)) - do_exit(errno); + do_exit(LEGAL_EOF); // hopefully remote has produced error message namebuf[hdr->namelen] = 0; if (S_ISREG(hdr->mode)) process_one_file_reg(hdr, namebuf);