Use gui_fatal in qfile-agent-dvm.c

This commit is contained in:
Rafal Wojtczuk 2011-03-15 13:12:21 +01:00
parent 237ce31f27
commit 29ffbfd474
2 changed files with 15 additions and 32 deletions

View File

@ -3,8 +3,8 @@ CFLAGS=-Wall -I../common
all: qubes_penctl qubes_add_pendrive_script qvm-open-in-dvm dvm_file_editor qfile-agent-dvm
dvm_file_editor: dvm_file_editor.o ../common/ioall.o
$(CC) -o dvm_file_editor dvm_file_editor.o ../common/ioall.o
qfile-agent-dvm: qfile-agent-dvm.o ../common/ioall.o
$(CC) -o qfile-agent-dvm qfile-agent-dvm.o ../common/ioall.o
qfile-agent-dvm: qfile-agent-dvm.o ../common/ioall.o ../common/gui-fatal.o
$(CC) -o qfile-agent-dvm qfile-agent-dvm.o ../common/ioall.o ../common/gui-fatal.o
qubes_penctl: qubes_penctl.o
$(CC) -o qubes_penctl qubes_penctl.o -lxenstore
qubes_add_pendrive_script: qubes_add_pendrive_script.o

View File

@ -9,32 +9,15 @@
#include <stdlib.h>
#include <ioall.h>
#include <unistd.h>
#include <gui-fatal.h>
#include "dvm2.h"
//the below usage of "system" is smelly, but should be fine - input comes from the same vm
void fatal(char *msg)
{
char *errcmd;
asprintf(&errcmd, "DISPLAY=:0 kdialog --sorry 'qfile-agent-dvm: %s'", msg);
system(errcmd);
perror(msg);
exit(1);
}
void nonfatal(char *msg)
{
char *errcmd;
asprintf(&errcmd, "DISPLAY=:0 kdialog --sorry 'qfile-agent-dvm: %s'", msg);
system(errcmd);
fprintf(stderr, "%s", msg);
}
void send_file(char *fname)
{
char *base;
int fd = open(fname, O_RDONLY);
if (fd < 0)
fatal("open file_to_be_edited");
gui_fatal("open %s", fname);
base = rindex(fname, '/');
if (!base)
base = fname;
@ -43,9 +26,9 @@ void send_file(char *fname)
if (strlen(base) >= DVM_FILENAME_SIZE)
base += strlen(base) - DVM_FILENAME_SIZE + 1;
if (!write_all(1, base, DVM_FILENAME_SIZE))
fatal("send filename");
gui_fatal("send filename to dispVM");
if (!copy_fd_all(1, fd))
fatal("send file");
gui_fatal("send file to dispVM");
close(1);
}
@ -53,9 +36,9 @@ int copy_and_return_nonemptiness(int tmpfd)
{
struct stat st;
if (!copy_fd_all(tmpfd, 0))
fatal("receiving file");
gui_fatal("receiving file from dispVM");
if (fstat(tmpfd, &st))
fatal("fstat");
gui_fatal("fstat");
close(tmpfd);
return st.st_size;
@ -70,7 +53,7 @@ void recv_file_nowrite(char *fname)
asprintf(&tempfile, "/tmp/file_edited_in_dvm.XXXXXX");
tmpfd = mkstemp(tempfile);
if (tmpfd < 0)
fatal("unable to create any temporary file, aborting");
gui_fatal("unable to create any temporary file, aborting");
if (!copy_and_return_nonemptiness(tmpfd)) {
unlink(tempfile);
return;
@ -79,7 +62,7 @@ void recv_file_nowrite(char *fname)
"The file %s has been edited in Disposable VM and the modified content has been received, "
"but this file is in nonwritable directory and thus cannot be modified safely. The edited file has been "
"saved to %s", fname, tempfile);
nonfatal(errmsg);
gui_nonfatal(errmsg);
}
void actually_recv_file(char *fname, char *tempfile, int tmpfd)
@ -89,7 +72,7 @@ void actually_recv_file(char *fname, char *tempfile, int tmpfd)
return;
}
if (rename(tempfile, fname))
fatal("rename");
gui_fatal("rename");
}
void recv_file(char *fname)
@ -121,13 +104,13 @@ void process_spoolentry(char *entry_name)
entry_fd = open(abs_spool_entry_name, O_RDONLY);
unlink(abs_spool_entry_name);
if (entry_fd < 0 || fstat(entry_fd, &st))
fatal("bad dvm_entry");
gui_fatal("bad dvm_entry");
entry_size = st.st_size;
filename = calloc(1, entry_size + DVM_FILENAME_SIZE);
if (!filename)
fatal("malloc");
gui_fatal("malloc");
if (!read_all(entry_fd, filename, entry_size))
fatal("read dvm entry");
gui_fatal("read dvm entry %s", abs_spool_entry_name);
close(entry_fd);
talk_to_daemon(filename);
}
@ -137,7 +120,7 @@ void scan_spool(char *name)
struct dirent *ent;
DIR *dir = opendir(name);
if (!dir)
fatal("opendir");
gui_fatal("opendir %s", name);
while ((ent = readdir(dir))) {
char *fname = ent->d_name;
if (!strcmp(fname, ".") || !strcmp(fname, ".."))