提交 850810d0 编写于 作者: J Justin M. Forbes 提交者: Anthony Liguori

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: NJustin M. Forbes <jforbes@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 6c098407
...@@ -844,8 +844,8 @@ static void load_linux(void *fw_cfg, ...@@ -844,8 +844,8 @@ static void load_linux(void *fw_cfg,
if (!f || !(kernel_size = get_file_size(f)) || if (!f || !(kernel_size = get_file_size(f)) ||
fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) !=
MIN(ARRAY_SIZE(header), kernel_size)) { MIN(ARRAY_SIZE(header), kernel_size)) {
fprintf(stderr, "qemu: could not load kernel '%s'\n", fprintf(stderr, "qemu: could not load kernel '%s': %s\n",
kernel_filename); kernel_filename, strerror(errno));
exit(1); exit(1);
} }
...@@ -950,8 +950,8 @@ static void load_linux(void *fw_cfg, ...@@ -950,8 +950,8 @@ static void load_linux(void *fw_cfg,
fi = fopen(initrd_filename, "rb"); fi = fopen(initrd_filename, "rb");
if (!fi) { if (!fi) {
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", fprintf(stderr, "qemu: could not load initial ram disk '%s': %s\n",
initrd_filename); initrd_filename, strerror(errno));
exit(1); exit(1);
} }
...@@ -959,8 +959,8 @@ static void load_linux(void *fw_cfg, ...@@ -959,8 +959,8 @@ static void load_linux(void *fw_cfg,
initrd_addr = (initrd_max-initrd_size) & ~4095; initrd_addr = (initrd_max-initrd_size) & ~4095;
if (!fread_targphys_ok(initrd_addr, initrd_size, fi)) { if (!fread_targphys_ok(initrd_addr, initrd_size, fi)) {
fprintf(stderr, "qemu: read error on initial ram disk '%s'\n", fprintf(stderr, "qemu: read error on initial ram disk '%s': %s\n",
initrd_filename); initrd_filename, strerror(errno));
exit(1); exit(1);
} }
fclose(fi); fclose(fi);
......
...@@ -2328,8 +2328,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, ...@@ -2328,8 +2328,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
} }
if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) { if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
fprintf(stderr, "qemu: could not open disk image %s\n", fprintf(stderr, "qemu: could not open disk image %s: %s\n",
file); file, strerror(errno));
return NULL; return NULL;
} }
...@@ -5566,7 +5566,7 @@ int main(int argc, char **argv, char **envp) ...@@ -5566,7 +5566,7 @@ int main(int argc, char **argv, char **envp)
if (len != 1) if (len != 1)
exit(1); exit(1);
else if (status == 1) { else if (status == 1) {
fprintf(stderr, "Could not acquire pidfile\n"); fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
exit(1); exit(1);
} else } else
exit(0); exit(0);
...@@ -5593,7 +5593,7 @@ int main(int argc, char **argv, char **envp) ...@@ -5593,7 +5593,7 @@ int main(int argc, char **argv, char **envp)
uint8_t status = 1; uint8_t status = 1;
write(fds[1], &status, 1); write(fds[1], &status, 1);
} else } else
fprintf(stderr, "Could not acquire pid file\n"); fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
exit(1); exit(1);
} }
#endif #endif
...@@ -5777,8 +5777,8 @@ int main(int argc, char **argv, char **envp) ...@@ -5777,8 +5777,8 @@ int main(int argc, char **argv, char **envp)
snprintf(label, sizeof(label), "serial%d", i); snprintf(label, sizeof(label), "serial%d", i);
serial_hds[i] = qemu_chr_open(label, devname, NULL); serial_hds[i] = qemu_chr_open(label, devname, NULL);
if (!serial_hds[i]) { if (!serial_hds[i]) {
fprintf(stderr, "qemu: could not open serial device '%s'\n", fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
devname); devname, strerror(errno));
exit(1); exit(1);
} }
} }
...@@ -5791,8 +5791,8 @@ int main(int argc, char **argv, char **envp) ...@@ -5791,8 +5791,8 @@ int main(int argc, char **argv, char **envp)
snprintf(label, sizeof(label), "parallel%d", i); snprintf(label, sizeof(label), "parallel%d", i);
parallel_hds[i] = qemu_chr_open(label, devname, NULL); parallel_hds[i] = qemu_chr_open(label, devname, NULL);
if (!parallel_hds[i]) { if (!parallel_hds[i]) {
fprintf(stderr, "qemu: could not open parallel device '%s'\n", fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
devname); devname, strerror(errno));
exit(1); exit(1);
} }
} }
...@@ -5805,8 +5805,8 @@ int main(int argc, char **argv, char **envp) ...@@ -5805,8 +5805,8 @@ int main(int argc, char **argv, char **envp)
snprintf(label, sizeof(label), "virtcon%d", i); snprintf(label, sizeof(label), "virtcon%d", i);
virtcon_hds[i] = qemu_chr_open(label, devname, NULL); virtcon_hds[i] = qemu_chr_open(label, devname, NULL);
if (!virtcon_hds[i]) { if (!virtcon_hds[i]) {
fprintf(stderr, "qemu: could not open virtio console '%s'\n", fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
devname); devname, strerror(errno));
exit(1); exit(1);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册