Improve error reporting on file access (#524695)

This commit is contained in:
Justin M. Forbes 2009-10-01 21:29:40 +00:00
parent 840b728482
commit c63c2b38da
2 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,121 @@
From a40f520f7b94d2a5de04c7ca3a7513a99c84e9ef Mon Sep 17 00:00:00 2001
From: Justin M. Forbes <jforbes@redhat.com>
Date: Thu, 1 Oct 2009 16:13:56 -0500
Subject: [PATCH] Improve error reporting on file access
By making the error reporting include strerror(errno), it gives the user
a bit more indication as to why qemu failed. This is particularly
important for people running qemu as a non root user.
Signed-off-by: Justin M. Forbes <jforbes@redhat.com>
---
hw/pc.c | 12 ++++++------
vl.c | 20 ++++++++++----------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/hw/pc.c b/hw/pc.c
index 3b226f4..7a184cd 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -841,8 +841,8 @@ static void load_linux(void *fw_cfg,
if (!f || !(kernel_size = get_file_size(f)) ||
fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) !=
MIN(ARRAY_SIZE(header), kernel_size)) {
- fprintf(stderr, "qemu: could not load kernel '%s'\n",
- kernel_filename);
+ fprintf(stderr, "qemu: could not load kernel '%s': %s\n",
+ kernel_filename, strerror(errno));
exit(1);
}
@@ -947,8 +947,8 @@ static void load_linux(void *fw_cfg,
fi = fopen(initrd_filename, "rb");
if (!fi) {
- fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
- initrd_filename);
+ fprintf(stderr, "qemu: could not load initial ram disk '%s': %s\n",
+ initrd_filename, strerror(errno));
exit(1);
}
@@ -956,8 +956,8 @@ static void load_linux(void *fw_cfg,
initrd_addr = (initrd_max-initrd_size) & ~4095;
if (!fread_targphys_ok(initrd_addr, initrd_size, fi)) {
- fprintf(stderr, "qemu: read error on initial ram disk '%s'\n",
- initrd_filename);
+ fprintf(stderr, "qemu: read error on initial ram disk '%s': %s\n",
+ initrd_filename, strerror(errno));
exit(1);
}
fclose(fi);
diff --git a/vl.c b/vl.c
index d7c7ab1..9182d89 100644
--- a/vl.c
+++ b/vl.c
@@ -2379,8 +2379,8 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
else if (cache == 2) /* write-back */
bdrv_flags |= BDRV_O_CACHE_WB;
if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
- fprintf(stderr, "qemu: could not open disk image %s\n",
- file);
+ fprintf(stderr, "qemu: could not open disk image %s: %s\n",
+ file, strerror(errno));
return -1;
}
if (bdrv_key_required(bdrv))
@@ -5799,7 +5799,7 @@ int main(int argc, char **argv, char **envp)
if (len != 1)
exit(1);
else if (status == 1) {
- fprintf(stderr, "Could not acquire pidfile\n");
+ fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
exit(1);
} else
exit(0);
@@ -5826,7 +5826,7 @@ int main(int argc, char **argv, char **envp)
uint8_t status = 1;
write(fds[1], &status, 1);
} else
- fprintf(stderr, "Could not acquire pid file\n");
+ fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
exit(1);
}
#endif
@@ -6031,8 +6031,8 @@ int main(int argc, char **argv, char **envp)
snprintf(label, sizeof(label), "serial%d", i);
serial_hds[i] = qemu_chr_open(label, devname, NULL);
if (!serial_hds[i]) {
- fprintf(stderr, "qemu: could not open serial device '%s'\n",
- devname);
+ fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
+ devname, strerror(errno));
exit(1);
}
}
@@ -6045,8 +6045,8 @@ int main(int argc, char **argv, char **envp)
snprintf(label, sizeof(label), "parallel%d", i);
parallel_hds[i] = qemu_chr_open(label, devname, NULL);
if (!parallel_hds[i]) {
- fprintf(stderr, "qemu: could not open parallel device '%s'\n",
- devname);
+ fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
+ devname, strerror(errno));
exit(1);
}
}
@@ -6059,8 +6059,8 @@ int main(int argc, char **argv, char **envp)
snprintf(label, sizeof(label), "virtcon%d", i);
virtcon_hds[i] = qemu_chr_open(label, devname, NULL);
if (!virtcon_hds[i]) {
- fprintf(stderr, "qemu: could not open virtio console '%s'\n",
- devname);
+ fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
+ devname, strerror(errno));
exit(1);
}
}
--
1.6.2.5

View File

@ -43,6 +43,9 @@ Patch05: qemu-correctly-free-nic-info-structure.patch
Patch06: qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch
Patch07: qemu-do-not-exit-on-pci-hotplug-invalid-nic2.patch
# Improve error reporting on file access
Patch08: qemu-improve-error-reporting-on-file-access.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: SDL-devel zlib-devel which texi2html gnutls-devel cyrus-sasl-devel
BuildRequires: rsync dev86 iasl
@ -233,6 +236,7 @@ such as kvmtrace and kvm_stat.
%patch05 -p1
%patch06 -p1
%patch07 -p1
%patch08 -p1
%build
# systems like rhel build system does not have a recent enough linker so
@ -526,6 +530,9 @@ fi
%{_mandir}/man1/qemu-img.1*
%changelog
* Thu Oct 1 2009 Justin M. Forbes <jmforbes@redhat.com> - 2:0.11.0-3
- Improve error reporting on file access (#524695)
* Mon Sep 28 2009 Mark McLoughlin <markmc@redhat.com> - 2:0.11.0-2
- Fix pci hotplug to not exit if supplied an invalid NIC model (#524022)