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