diff --git a/appvm/qfile-agent.c b/appvm/qfile-agent.c index 530bbb2..4b37738 100644 --- a/appvm/qfile-agent.c +++ b/appvm/qfile-agent.c @@ -20,24 +20,33 @@ enum { }; unsigned long crc32_sum; -int write_all_with_crc(int fd, void *buf, int size) { +int write_all_with_crc(int fd, void *buf, int size) +{ crc32_sum = Crc32_ComputeBuf(crc32_sum, buf, size); return write_all(fd, buf, size); } - -char *client_flags; void do_notify_progress(long long total, int flag) { - FILE *progress; - if (!client_flags[0]) + char *du_size_env = getenv("FILECOPY_TOTAL_SIZE"); + char *progress_type_env = getenv("PROGRESS_TYPE"); + char *saved_stdout_env = getenv("SAVED_FD_1"); + if (!progress_type_env) return; - progress = fopen(client_flags, "w"); - if (!progress) - return; - fprintf(progress, "%d %lld %s", getpid(), total, - flag == PROGRESS_FLAG_DONE ? "DONE" : "BUSY"); - fclose(progress); + if (!strcmp(progress_type_env, "console") && du_size_env) { + char msg[256]; + snprintf(msg, sizeof(msg), "sent %lld/%lld KB\r", + total / 1024, strtoull(du_size_env, NULL, 0)); + write(2, msg, strlen(msg)); + if (flag == PROGRESS_FLAG_DONE) + write(2, "\n", 1); + } + if (!strcmp(progress_type_env, "gui") && saved_stdout_env) { + char msg[256]; + snprintf(msg, sizeof(msg), "%lld\n", total); + write(strtoul(saved_stdout_env, NULL, 0), msg, + strlen(msg)); + } } void notify_progress(int size, int flag) @@ -136,25 +145,6 @@ int do_fs_walk(char *file) return 0; } -void send_vmname(char *vmname) -{ - char buf[FILECOPY_VMNAME_SIZE]; - memset(buf, 0, sizeof(buf)); - strncat(buf, vmname, sizeof(buf) - 1); - if (!write_all(1, buf, sizeof buf)) - exit(1); -} - -char *get_item(char *data, char **current, int size) -{ - char *ret; - if ((unsigned long) *current >= (unsigned long) data + size) - return NULL; - ret = *current; - *current += strlen(ret) + 1; - return ret; -} - void notify_end_and_wait_for_result() { struct result_header hdr; @@ -168,26 +158,40 @@ void notify_end_and_wait_for_result() /* wait for result */ if (!read_all(0, &hdr, sizeof(hdr))) { - exit(1); // hopefully remote has produced error message + exit(1); // hopefully remote has produced error message } if (hdr.error_code != 0) { - gui_fatal("Error writing files: %s", strerror(hdr.error_code)); + gui_fatal("Error writing files: %s", + strerror(hdr.error_code)); } if (hdr.crc32 != crc32_sum) { gui_fatal("File transfer failed: checksum mismatch"); } } -void parse_entry(char *data, int datasize) +char *get_abs_path(char *cwd, char *pathname) { - char *current = data; - char *vmname, *entry, *sep; - vmname = get_item(data, ¤t, datasize); - client_flags = get_item(data, ¤t, datasize); + char *ret; + if (pathname[0] == '/') + return strdup(pathname); + asprintf(&ret, "%s/%s", cwd, pathname); + return ret; +} + +int main(int argc, char **argv) +{ + int i; + char *entry; + char *cwd; + char *sep; + + signal(SIGPIPE, SIG_IGN); notify_progress(0, PROGRESS_FLAG_INIT); - send_vmname(vmname); crc32_sum = 0; - while ((entry = get_item(data, ¤t, datasize))) { + cwd = getcwd(NULL, 0); + for (i = 1; i < argc; i++) { + entry = get_abs_path(cwd, argv[i]); + do { sep = rindex(entry, '/'); if (!sep) @@ -200,53 +204,9 @@ void parse_entry(char *data, int datasize) else if (chdir(entry)) gui_fatal("chdir to %s", entry); do_fs_walk(sep + 1); + free(entry); } notify_end_and_wait_for_result(); notify_progress(0, PROGRESS_FLAG_DONE); -} - -void process_spoolentry(char *entry_name) -{ - char *abs_spool_entry_name; - int entry_fd; - struct stat st; - char *entry; - int entry_size; - asprintf(&abs_spool_entry_name, "%s/%s", FILECOPY_SPOOL, - entry_name); - entry_fd = open(abs_spool_entry_name, O_RDONLY); - unlink(abs_spool_entry_name); - if (entry_fd < 0 || fstat(entry_fd, &st)) - gui_fatal("bad file copy spool entry"); - entry_size = st.st_size; - entry = calloc(1, entry_size + 1); - if (!entry) - gui_fatal("malloc"); - if (!read_all(entry_fd, entry, entry_size)) - gui_fatal("read filecopy entry"); - close(entry_fd); - parse_entry(entry, entry_size); -} - -void scan_spool(char *name) -{ - struct dirent *ent; - DIR *dir = opendir(name); - if (!dir) - gui_fatal("opendir %s", name); - while ((ent = readdir(dir))) { - char *fname = ent->d_name; - if (fname[0] != '.') { - process_spoolentry(fname); - break; - } - } - closedir(dir); -} - -int main() -{ - signal(SIGPIPE, SIG_IGN); - scan_spool(FILECOPY_SPOOL); return 0; } diff --git a/appvm/qvm-copy-to-vm b/appvm/qvm-copy-to-vm index eaf8c8f..bcf333d 100755 --- a/appvm/qvm-copy-to-vm +++ b/appvm/qvm-copy-to-vm @@ -20,50 +20,24 @@ # # -if [ x"$1" = "x--without-progress" ] ; then - DO_PROGRESS=0 - shift -else - DO_PROGRESS=1 -fi - if [ $# -lt 2 ] ; then echo usage: $0 '[--without-progress] dest_vmname file [file]+' exit 1 fi +if [ x"$1" = "x--without-progress" ] ; then + export PROGRESS_TYPE=none + shift +else + export PROGRESS_TYPE=console +fi + + VM="$1" shift -if [ $DO_PROGRESS = 1 ] ; then - SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) +if [ $PROGRESS_TYPE = console ] ; then + export FILECOPY_TOTAL_SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) fi -export PROGRESS_FILE=$(mktemp) -/usr/lib/qubes/qvm-trigger-copy-to-vm $VM "$@" -while ! [ -s $PROGRESS_FILE ] ; do - sleep 0.1 -done - -while true ; do - read agentpid sentsize agentstatus < $PROGRESS_FILE - if [ "x"$agentstatus = x ] ; then continue ; fi - if ! [ -e /proc/$agentpid ] ; then break ; fi - if [ "x"$agentstatus = xDONE ] ; then break ; fi - CURRSIZE=$(($sentsize/1024)) - if [ $DO_PROGRESS = 1 ] ; then - echo -ne "\r sent $CURRSIZE/$SIZE KB " - fi - sleep 0.4 -done - -rm -f $PROGRESS_FILE -if [ $DO_PROGRESS = 1 ] ; then - echo -fi - -if ! [ "x"$agentstatus = xDONE ] ; then - exit 1 -else - exit 0 -fi +exec /usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent $VM qubes.Filecopy "$@" diff --git a/appvm/qvm-copy-to-vm2.gnome b/appvm/qvm-copy-to-vm2.gnome index 8fabd2d..be9dc7e 100755 --- a/appvm/qvm-copy-to-vm2.gnome +++ b/appvm/qvm-copy-to-vm2.gnome @@ -25,19 +25,11 @@ if [ X$VM = X ] ; then exit 0 ; fi SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) -export PROGRESS_FILE=$(mktemp) -/usr/lib/qubes/qvm-trigger-copy-to-vm $VM "$@" -while ! [ -s $PROGRESS_FILE ] ; do - sleep 0.1 -done -(while true ; do - read agentpid sentsize agentstatus < $PROGRESS_FILE - if [ "x"$agentstatus = x ] ; then continue ; fi - if ! [ -e /proc/$agentpid ] ; then break ; fi - if [ "x"$agentstatus = xdone ] ; then break ; fi +export PROGRESS_TYPE=gui + +/usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent \ + $VM qubes.Filecopy "$@" | +(while read sentsize ; do CURRSIZE=$(($sentsize/1024)) echo $((100*$CURRSIZE/$SIZE)) - sleep 0.1 done) | zenity --progress --text="Copying files to domain: $VM..." --auto-close - -rm -f $PROGRESS_FILE diff --git a/appvm/qvm-copy-to-vm2.kde b/appvm/qvm-copy-to-vm2.kde index 7600bb5..478df92 100755 --- a/appvm/qvm-copy-to-vm2.kde +++ b/appvm/qvm-copy-to-vm2.kde @@ -27,23 +27,16 @@ SIZE=$(du --apparent-size -c "$@" | tail -1 | cut -f 1) REF=$(kdialog --progressbar "Copy progress") qdbus $REF org.freedesktop.DBus.Properties.Set "" maximum $SIZE -export PROGRESS_FILE=$(mktemp) -/usr/lib/qubes/qvm-trigger-copy-to-vm $VM "$@" -while ! [ -s $PROGRESS_FILE ] ; do - sleep 0.1 -done -while true ; do - read agentpid sentsize agentstatus < $PROGRESS_FILE - if [ "x"$agentstatus = x ] ; then continue ; fi - if ! [ -e /proc/$agentpid ] ; then break ; fi - if [ "x"$agentstatus = xdone ] ; then break ; fi +export PROGRESS_TYPE=gui + +/usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qfile-agent \ + $VM qubes.Filecopy "$@" | +(while read sentsize ; do CURRSIZE=$(($sentsize/1024)) qdbus $REF org.freedesktop.DBus.Properties.Set "" value $CURRSIZE - sleep 0.4 -done +done) qdbus $REF close -rm -f $PROGRESS_FILE # 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' diff --git a/appvm/qvm-trigger-copy-to-vm b/appvm/qvm-trigger-copy-to-vm deleted file mode 100755 index 56dcdef..0000000 --- a/appvm/qvm-trigger-copy-to-vm +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# The Qubes OS Project, http://www.qubes-os.org -# -# Copyright (C) 2010 Rafal Wojtczuk -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# - -if [ $# -lt 2 ] ; then - echo usage: $0 'vmname file [file]*' - exit 1 -fi - -FILECOPY_SPOOL=/home/user/.filecopyspool -if ! [ -e $FILECOPY_SPOOL ] ; then - mkdir $FILECOPY_SPOOL -fi - -REQ_FILE_TMP=$FILECOPY_SPOOL/.req.$$ -echo -ne "$1""\x00" > $REQ_FILE_TMP -echo -ne "$PROGRESS_FILE""\x00" >> $REQ_FILE_TMP - -shift -for FILE in "$@" ; do - if ! [ "X""${FILE:0:1}" = X/ ] ; then - FILE="$PWD"/"$FILE" - fi - echo -ne "$FILE""\x00" >> $REQ_FILE_TMP -done - -mv $REQ_FILE_TMP $FILECOPY_SPOOL/req.$$ -echo -n FCPR > /var/run/qubes/qrexec_agent diff --git a/rpm_spec/core-appvm.spec b/rpm_spec/core-appvm.spec index dfc7e06..7786259 100644 --- a/rpm_spec/core-appvm.spec +++ b/rpm_spec/core-appvm.spec @@ -79,7 +79,6 @@ cp qvm-copy-to-vm $RPM_BUILD_ROOT/usr/bin mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes cp qvm-copy-to-vm2.kde $RPM_BUILD_ROOT/usr/lib/qubes cp qvm-copy-to-vm2.gnome $RPM_BUILD_ROOT/usr/lib/qubes -cp qvm-trigger-copy-to-vm $RPM_BUILD_ROOT/usr/lib/qubes cp ../qrexec/qrexec_agent $RPM_BUILD_ROOT/usr/lib/qubes cp ../qrexec/qrexec_client_vm $RPM_BUILD_ROOT/usr/lib/qubes cp ../qrexec/qubes_rpc_multiplexer $RPM_BUILD_ROOT/usr/lib/qubes @@ -89,6 +88,7 @@ mkdir -p $RPM_BUILD_ROOT/%{kde_service_dir} cp qvm-copy.desktop qvm-dvm.desktop $RPM_BUILD_ROOT/%{kde_service_dir} mkdir -p $RPM_BUILD_ROOT/mnt/removable mkdir -p $RPM_BUILD_ROOT/etc/qubes_rpc +cp qubes.Filecopy $RPM_BUILD_ROOT/etc/qubes_rpc mkdir -p $RPM_BUILD_ROOT/etc/X11 @@ -144,7 +144,6 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/qubes/dvm_file_editor %{kde_service_dir}/qvm-copy.desktop %{kde_service_dir}/qvm-dvm.desktop -/usr/lib/qubes/qvm-trigger-copy-to-vm /usr/lib/qubes/qrexec_agent /usr/lib/qubes/qrexec_client_vm /usr/lib/qubes/qubes_rpc_multiplexer @@ -153,6 +152,7 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/qubes/qfile-unpacker %dir /mnt/removable %dir /etc/qubes_rpc +/etc/qubes_rpc/qubes.Filecopy /usr/bin/qubes_timestamp %dir /home_volatile %attr(700,user,user) /home_volatile/user