mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
char: error out if given unhandled size options
This is a small help, because in fact all combined chardev options are accepted by qemu_chardev_opts[]. But given that a user may legitimately want to use the size options with a VC backend, we can report an error when we know the backend doesn't support it. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
@@ -639,6 +639,18 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!cc->supports_size_opts) {
|
||||
const char * const invalid_opts[] = {
|
||||
"width", "height", "cols", "rows", NULL
|
||||
};
|
||||
|
||||
if (qemu_opt_has_any(opts, invalid_opts)) {
|
||||
error_setg(errp, "chardev '%s' does not support size options",
|
||||
qemu_opts_id(opts));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
backend = g_new0(ChardevBackend, 1);
|
||||
backend->type = CHARDEV_BACKEND_KIND_NULL;
|
||||
|
||||
|
||||
@@ -254,6 +254,7 @@ struct ChardevClass {
|
||||
|
||||
bool internal; /* TODO: eventually use TYPE_USER_CREATABLE */
|
||||
bool supports_yank;
|
||||
bool supports_size_opts;
|
||||
|
||||
/* parse command line options and populate QAPI @backend */
|
||||
void (*chr_parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
|
||||
|
||||
@@ -73,6 +73,7 @@ struct QemuOptsList {
|
||||
|
||||
const char *qemu_opt_get(QemuOpts *opts, const char *name);
|
||||
char *qemu_opt_get_del(QemuOpts *opts, const char *name);
|
||||
bool qemu_opt_has_any(QemuOpts *opts, const char * const *names);
|
||||
/**
|
||||
* qemu_opt_has_help_opt:
|
||||
* @opts: options to search for a help request
|
||||
|
||||
@@ -1251,6 +1251,7 @@ static void char_vc_class_init(ObjectClass *oc, const void *data)
|
||||
cc->chr_write = vc_chr_write;
|
||||
cc->chr_accept_input = vc_chr_accept_input;
|
||||
cc->chr_set_echo = vc_chr_set_echo;
|
||||
cc->supports_size_opts = true;
|
||||
}
|
||||
|
||||
static const TypeInfo char_vc_type_info = {
|
||||
|
||||
@@ -271,6 +271,19 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
|
||||
return opt->str;
|
||||
}
|
||||
|
||||
bool qemu_opt_has_any(QemuOpts *opts, const char * const *names)
|
||||
{
|
||||
int it;
|
||||
|
||||
for (it = 0; names[it]; it++) {
|
||||
if (qemu_opt_get(opts, names[it])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void qemu_opt_iter_init(QemuOptsIter *iter, QemuOpts *opts, const char *name)
|
||||
{
|
||||
iter->opts = opts;
|
||||
|
||||
Reference in New Issue
Block a user