Patchwork [18/19] qemu-char: Chardev open error reporting, generic part

login
register
mail settings
Submitter Markus Armbruster
Date Feb. 7, 2012, 2:09 p.m.
Message ID <1328623766-12287-19-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/139937/
State New
Headers show

Comments

Markus Armbruster - Feb. 7, 2012, 2:09 p.m.
1. Convert to error_report().

2. All backends now report their errors, no need to follow up with an
unspecific "opening backend failed".  Drop the message.

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

Patch

diff --git a/qemu-char.c b/qemu-char.c
index ecbb595..fe0cfce 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2808,33 +2808,30 @@  static const struct {
 CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
                                     void (*init)(struct CharDriverState *s))
 {
+    const char *backend = qemu_opt_get(opts, "backend");
     CharDriverState *chr;
     int i;
 
     if (qemu_opts_id(opts) == NULL) {
-        fprintf(stderr, "chardev: no id specified\n");
+        error_report("character device requires parameter id");
         return NULL;
     }
 
-    if (qemu_opt_get(opts, "backend") == NULL) {
-        fprintf(stderr, "chardev: \"%s\" missing backend\n",
-                qemu_opts_id(opts));
+    if (!backend) {
+        error_report("character device requires parameter backend");
         return NULL;
     }
     for (i = 0; i < ARRAY_SIZE(backend_table); i++) {
-        if (strcmp(backend_table[i].name, qemu_opt_get(opts, "backend")) == 0)
+        if (strcmp(backend_table[i].name, backend) == 0)
             break;
     }
     if (i == ARRAY_SIZE(backend_table)) {
-        fprintf(stderr, "chardev: backend \"%s\" not found\n",
-                qemu_opt_get(opts, "backend"));
+        error_report("character device backend '%s' not found", backend);
         return NULL;
     }
 
     chr = backend_table[i].open(opts);
     if (!chr) {
-        fprintf(stderr, "chardev: opening backend \"%s\" failed\n",
-                qemu_opt_get(opts, "backend"));
         return NULL;
     }