[12/19] qemu-char: Chardev open error reporting, tty part

Message ID 1328623766-12287-13-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Feb. 7, 2012, 2:09 p.m.
Unlike many other backends, this one leaves open error reporting to
its caller.  Because the caller doesn't know what went wrong, this
results in a pretty useless error message.

Change it to report its errors.  Improves user-hostile messages like
this one for "-chardev tty,id=foo,path=/dev/ttyy1"

    chardev: opening backend "file" failed


    qemu-system-x86_64: -chardev tty,id=foo,path=/dev/ttyy1: Can't open '/dev/ttyy1': No such file or directory
    chardev: opening backend "file" failed

The useless "opening backend failed" message will be cleaned up

Signed-off-by: Markus Armbruster <armbru@redhat.com>
 qemu-char.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)


diff --git a/qemu-char.c b/qemu-char.c
index 130ed8b..1ff7f4b 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1231,8 +1231,14 @@  static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
     CharDriverState *chr;
     int fd;
+    if (!filename) {
+        error_report("tty character device requires parameter path");
+        return NULL;
+    }
     TFR(fd = qemu_open(filename, O_RDWR | O_NONBLOCK));
     if (fd < 0) {
+        error_report("Can't open '%s': %s", filename, strerror(errno));
         return NULL;
     tty_serial_init(fd, 115200, 'N', 8, 1);