From 71df1d833776647fc12f5bbcd6d6fe4c5e931094 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Mar 2015 08:40:25 +0100 Subject: QemuOpts: Convert qemu_opt_foreach() to Error Retain the function value for now, to permit selective conversion of its callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- util/qemu-config.c | 5 +++-- util/qemu-option.c | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'util') diff --git a/util/qemu-config.c b/util/qemu-config.c index aff4cb37c0..35adfda496 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -335,7 +335,8 @@ struct ConfigWriteData { FILE *fp; }; -static int config_write_opt(const char *name, const char *value, void *opaque) +static int config_write_opt(void *opaque, const char *name, const char *value, + Error **errp) { struct ConfigWriteData *data = opaque; @@ -353,7 +354,7 @@ static int config_write_opts(void *opaque, QemuOpts *opts, Error **errp) } else { fprintf(data->fp, "[%s]\n", data->list->name); } - qemu_opt_foreach(opts, config_write_opt, data); + qemu_opt_foreach(opts, config_write_opt, data, NULL); fprintf(data->fp, "\n"); return 0; } diff --git a/util/qemu-option.c b/util/qemu-option.c index 296e2b3fae..840f5f7a5b 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -597,20 +597,23 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, } /** - * For each member of @opts, call @func(name, value, @opaque). + * For each member of @opts, call @func(@opaque, name, value, @errp). + * @func() may store an Error through @errp, but must return non-zero then. * When @func() returns non-zero, break the loop and return that value. * Return zero when the loop completes. */ -int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque) +int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, + Error **errp) { QemuOpt *opt; int rc; QTAILQ_FOREACH(opt, &opts->head, next) { - rc = func(opt->name, opt->str, opaque); + rc = func(opaque, opt->name, opt->str, errp); if (rc) { return rc; } + assert(!errp || !*errp); } return 0; } -- cgit v1.2.3