From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/7] qdev: Fix exit code for -device ?
Date: Fri, 29 Jan 2010 19:48:57 +0100 [thread overview]
Message-ID: <1264790942-15045-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1264790942-15045-1-git-send-email-armbru@redhat.com>
Help was shoehorned into device creation, qdev_device_add(). Since
help doesn't create a device, it returns NULL, which looks to callers
just like failed device creation. Monitor handler do_device_add()
doesn't care, but main() exits unsuccessfully.
Move help out of device creation, into new qdev_device_help().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/qdev.c | 28 +++++++++++++++++++---------
hw/qdev.h | 1 +
vl.c | 8 ++++++++
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index c643576..f47f0cb 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -153,6 +153,24 @@ static int set_property(const char *name, const char *value, void *opaque)
return 0;
}
+int qdev_device_help(QemuOpts *opts)
+{
+ const char *driver;
+ DeviceInfo *info;
+ char msg[256];
+
+ driver = qemu_opt_get(opts, "driver");
+ if (driver && !strcmp(driver, "?")) {
+ for (info = device_info_list; info != NULL; info = info->next) {
+ qdev_print_devinfo(info, msg, sizeof(msg));
+ qemu_error("%s\n", msg);
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
DeviceState *qdev_device_add(QemuOpts *opts)
{
const char *driver, *path, *id;
@@ -165,14 +183,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
qemu_error("-device: no driver specified\n");
return NULL;
}
- if (strcmp(driver, "?") == 0) {
- char msg[256];
- for (info = device_info_list; info != NULL; info = info->next) {
- qdev_print_devinfo(info, msg, sizeof(msg));
- qemu_error("%s\n", msg);
- }
- return NULL;
- }
/* find driver */
info = qdev_find_info(NULL, driver);
@@ -726,7 +736,7 @@ void do_device_add(Monitor *mon, const QDict *qdict)
opts = qemu_opts_parse(&qemu_device_opts,
qdict_get_str(qdict, "config"), "driver");
- if (opts)
+ if (opts && !qdev_device_help(opts))
qdev_device_add(opts);
}
diff --git a/hw/qdev.h b/hw/qdev.h
index 07b9603..0eb45b0 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -104,6 +104,7 @@ typedef struct GlobalProperty {
/*** Board API. This should go away once we have a machine config file. ***/
DeviceState *qdev_create(BusState *bus, const char *name);
+int qdev_device_help(QemuOpts *opts);
DeviceState *qdev_device_add(QemuOpts *opts);
int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
void qdev_init_nofail(DeviceState *dev);
diff --git a/vl.c b/vl.c
index 6f1e1ab..39833fc 100644
--- a/vl.c
+++ b/vl.c
@@ -4459,6 +4459,11 @@ char *qemu_find_file(int type, const char *name)
return buf;
}
+static int device_help_func(QemuOpts *opts, void *opaque)
+{
+ return qdev_device_help(opts);
+}
+
static int device_init_func(QemuOpts *opts, void *opaque)
{
DeviceState *dev;
@@ -5828,6 +5833,9 @@ int main(int argc, char **argv, char **envp)
module_call_init(MODULE_INIT_DEVICE);
+ if (qemu_opts_foreach(&qemu_device_opts, device_help_func, NULL, 0) != 0)
+ exit(0);
+
if (watchdog) {
i = select_watchdog(watchdog);
if (i > 0)
--
1.6.6
next prev parent reply other threads:[~2010-01-29 18:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-29 18:48 [Qemu-devel] [PATCH 0/7] Clean up -device help Markus Armbruster
2010-01-29 18:48 ` [Qemu-devel] [PATCH 1/7] qemu-option: Make qemu_opts_foreach() accumulate return values Markus Armbruster
2010-02-03 18:51 ` Anthony Liguori
2010-01-29 18:48 ` Markus Armbruster [this message]
2010-01-29 18:48 ` [Qemu-devel] [PATCH 3/7] Revert "qdev: Add help for property value" Markus Armbruster
2010-01-29 18:48 ` [Qemu-devel] [PATCH 4/7] Revert "qdev: Add help for device properties" Markus Armbruster
2010-01-29 18:49 ` [Qemu-devel] [PATCH 5/7] qdev: Add help for device properties Markus Armbruster
2010-01-29 18:49 ` [Qemu-devel] [PATCH 6/7] qdev: update help on -device Markus Armbruster
2010-01-29 18:49 ` [Qemu-devel] [PATCH 7/7] qdev: Add rudimentary help for property value Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264790942-15045-3-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).