Skip to contentSkip to conversation

char: don't exit on hmp 'chardev-add help'

PATCH Applied Anton Nefedov 2 participants 2 messages Jul 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 char: don't exit on hmp 'chardev-add help'

qemu_chr_new_from_opts() is used from both vl.c and hmp,
and it is quite confusing to see qemu suddenly exit after receiving a help option in hmp.

Do exit(0) from vl.c instead.

---
 include/chardev/char.h |  4 +++-
 chardev/char.c         |  2 +-
 vl.c                   | 10 ++++++----
 3 files changed, 10 insertions(+), 6 deletions(-)
include/chardev/char.h +3 -1
index 1604ea9..66dde46 100644
@@ -65,7 +65,9 @@ struct Chardev {
  *
  * @opts see qemu-config.c for a list of valid options
  *
- * Returns: a new character backend
+ * Returns: on success: a new character backend
+ *          otherwise:  NULL; @errp specifies the error
+ *                            or left untouched in case of help option
  */
 Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
                                 Error **errp);
chardev/char.c +1 -1
index c34b44a..5d283b9 100644
@@ -620,7 +620,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)
 
         error_report("Available chardev backend types: %s", str->str);
         g_string_free(str, true);
-        exit(0);
+        return NULL;
     }
 
     if (id == NULL) {
vl.c +6 -4
index fb6b2ef..47bfe51 100644
@@ -2344,10 +2344,12 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     Error *local_err = NULL;
 
-    qemu_chr_new_from_opts(opts, &local_err);
-    if (local_err) {
-        error_report_err(local_err);
-        return -1;
+    if (!qemu_chr_new_from_opts(opts, &local_err)) {
+        if (local_err) {
+            error_report_err(local_err);
+            return -1;
+        }
+        exit(0);
     }
     return 0;
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Anton Nefedov

qemu_chr_new_from_opts() is used from both vl.c and hmp,
and it is quite confusing to see qemu suddenly exit after receiving a help option in hmp.

Do exit(0) from vl.c instead.

Queued, thanks.

Paolo

Quoted 57 lines
---
 include/chardev/char.h |  4 +++-
 chardev/char.c         |  2 +-
 vl.c                   | 10 ++++++----
 3 files changed, 10 insertions(+), 6 deletions(-)
include/chardev/char.h +3 -1
index 1604ea9..66dde46 100644
@@ -65,7 +65,9 @@ struct Chardev {
  *
  * @opts see qemu-config.c for a list of valid options
  *
- * Returns: a new character backend
+ * Returns: on success: a new character backend
+ *          otherwise:  NULL; @errp specifies the error
+ *                            or left untouched in case of help option
  */
 Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
                                 Error **errp);
chardev/char.c +1 -1
index c34b44a..5d283b9 100644
@@ -620,7 +620,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)
 
         error_report("Available chardev backend types: %s", str->str);
         g_string_free(str, true);
-        exit(0);
+        return NULL;
     }
 
     if (id == NULL) {
vl.c +6 -4
index fb6b2ef..47bfe51 100644
@@ -2344,10 +2344,12 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     Error *local_err = NULL;
 
-    qemu_chr_new_from_opts(opts, &local_err);
-    if (local_err) {
-        error_report_err(local_err);
-        return -1;
+    if (!qemu_chr_new_from_opts(opts, &local_err)) {
+        if (local_err) {
+            error_report_err(local_err);
+            return -1;
+        }
+        exit(0);
     }
     return 0;
 }