aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-02-12 17:52:20 +0100
committerMarkus Armbruster <armbru@redhat.com>2015-02-26 14:49:31 +0100
commitf43e47dbf6de24db20ec9b588bb6cc762093dd69 (patch)
treee6236f3afaabde624458eab11e8daaa7e0dd4878 /util
parent6be4194b9215ed29f258543ce34a1b4b2003864d (diff)
QemuOpts: Drop qemu_opt_set(), rename qemu_opt_set_err(), fix use
qemu_opt_set() is a wrapper around qemu_opt_set() that reports the error with qerror_report_err(). Most of its users assume the function can't fail. Make them use qemu_opt_set_err() with &error_abort, so that should the assumption ever break, it'll break noisily. Just two users remain, in util/qemu-config.c. Switch them to qemu_opt_set_err() as well, then rename qemu_opt_set_err() to qemu_opt_set(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-config.c9
-rw-r--r--util/qemu-option.c22
-rw-r--r--util/qemu-sockets.c34
3 files changed, 29 insertions, 36 deletions
diff --git a/util/qemu-config.c b/util/qemu-config.c
index b13efe2788..f3463df678 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -219,6 +219,7 @@ void qemu_add_opts(QemuOptsList *list)
int qemu_set_option(const char *str)
{
+ Error *local_err = NULL;
char group[64], id[64], arg[64];
QemuOptsList *list;
QemuOpts *opts;
@@ -242,7 +243,9 @@ int qemu_set_option(const char *str)
return -1;
}
- if (qemu_opt_set(opts, arg, str+offset+1) == -1) {
+ qemu_opt_set(opts, arg, str + offset + 1, &local_err);
+ if (local_err) {
+ error_report_err(local_err);
return -1;
}
return 0;
@@ -335,7 +338,9 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
error_report("no group defined");
goto out;
}
- if (qemu_opt_set(opts, arg, value) != 0) {
+ qemu_opt_set(opts, arg, value, &local_err);
+ if (local_err) {
+ error_report_err(local_err);
goto out;
}
continue;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 56711ca11c..928b86f0b0 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -548,22 +548,8 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
}
}
-int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
-{
- Error *local_err = NULL;
-
- opt_set(opts, name, value, false, &local_err);
- if (local_err) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
- }
-
- return 0;
-}
-
-void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
- Error **errp)
+void qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
+ Error **errp)
{
opt_set(opts, name, value, false, errp);
}
@@ -701,7 +687,7 @@ void qemu_opts_set(QemuOptsList *list, const char *id,
error_propagate(errp, local_err);
return;
}
- qemu_opt_set_err(opts, name, value, errp);
+ qemu_opt_set(opts, name, value, errp);
}
const char *qemu_opts_id(QemuOpts *opts)
@@ -921,7 +907,7 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
return;
}
- qemu_opt_set_err(state->opts, key, value, state->errp);
+ qemu_opt_set(state->opts, key, value, state->errp);
}
/*
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 7205dad820..e9085237c6 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -200,10 +200,12 @@ listen:
return -1;
}
snprintf(uport, sizeof(uport), "%d", inet_getport(e) - port_offset);
- qemu_opt_set(opts, "host", uaddr);
- qemu_opt_set(opts, "port", uport);
- qemu_opt_set(opts, "ipv6", (e->ai_family == PF_INET6) ? "on" : "off");
- qemu_opt_set(opts, "ipv4", (e->ai_family != PF_INET6) ? "on" : "off");
+ qemu_opt_set(opts, "host", uaddr, &error_abort);
+ qemu_opt_set(opts, "port", uport, &error_abort);
+ qemu_opt_set(opts, "ipv6", (e->ai_family == PF_INET6) ? "on" : "off",
+ &error_abort);
+ qemu_opt_set(opts, "ipv4", (e->ai_family != PF_INET6) ? "on" : "off",
+ &error_abort);
freeaddrinfo(res);
return slisten;
}
@@ -586,10 +588,10 @@ static void inet_addr_to_opts(QemuOpts *opts, const InetSocketAddress *addr)
if (addr->has_to) {
char to[20];
snprintf(to, sizeof(to), "%d", addr->to);
- qemu_opt_set(opts, "to", to);
+ qemu_opt_set(opts, "to", to, &error_abort);
}
- qemu_opt_set(opts, "host", addr->host);
- qemu_opt_set(opts, "port", addr->port);
+ qemu_opt_set(opts, "host", addr->host, &error_abort);
+ qemu_opt_set(opts, "port", addr->port, &error_abort);
}
int inet_listen(const char *str, char *ostr, int olen,
@@ -726,7 +728,7 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
goto err;
}
close(fd);
- qemu_opt_set(opts, "path", un.sun_path);
+ qemu_opt_set(opts, "path", un.sun_path, &error_abort);
}
unlink(un.sun_path);
@@ -838,11 +840,11 @@ int unix_listen(const char *str, char *ostr, int olen, Error **errp)
if (len) {
path = g_malloc(len+1);
snprintf(path, len+1, "%.*s", len, str);
- qemu_opt_set(opts, "path", path);
+ qemu_opt_set(opts, "path", path, &error_abort);
g_free(path);
}
} else {
- qemu_opt_set(opts, "path", str);
+ qemu_opt_set(opts, "path", str, &error_abort);
}
sock = unix_listen_opts(opts, errp);
@@ -859,7 +861,7 @@ int unix_connect(const char *path, Error **errp)
int sock;
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
- qemu_opt_set(opts, "path", path);
+ qemu_opt_set(opts, "path", path, &error_abort);
sock = unix_connect_opts(opts, errp, NULL, NULL);
qemu_opts_del(opts);
return sock;
@@ -876,7 +878,7 @@ int unix_nonblocking_connect(const char *path,
g_assert(callback != NULL);
opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
- qemu_opt_set(opts, "path", path);
+ qemu_opt_set(opts, "path", path, &error_abort);
sock = unix_connect_opts(opts, errp, callback, opaque);
qemu_opts_del(opts);
return sock;
@@ -933,7 +935,7 @@ int socket_connect(SocketAddress *addr, Error **errp,
break;
case SOCKET_ADDRESS_KIND_UNIX:
- qemu_opt_set(opts, "path", addr->q_unix->path);
+ qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort);
fd = unix_connect_opts(opts, errp, callback, opaque);
break;
@@ -965,7 +967,7 @@ int socket_listen(SocketAddress *addr, Error **errp)
break;
case SOCKET_ADDRESS_KIND_UNIX:
- qemu_opt_set(opts, "path", addr->q_unix->path);
+ qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort);
fd = unix_listen_opts(opts, errp);
break;
@@ -990,8 +992,8 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)
case SOCKET_ADDRESS_KIND_INET:
inet_addr_to_opts(opts, remote->inet);
if (local) {
- qemu_opt_set(opts, "localaddr", local->inet->host);
- qemu_opt_set(opts, "localport", local->inet->port);
+ qemu_opt_set(opts, "localaddr", local->inet->host, &error_abort);
+ qemu_opt_set(opts, "localport", local->inet->port, &error_abort);
}
fd = inet_dgram_opts(opts, errp);
break;