]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
char: error out if given unhandled size options
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 23 Apr 2026 11:20:53 +0000 (15:20 +0400)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Sat, 9 May 2026 06:24:30 +0000 (10:24 +0400)
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>
chardev/char.c
include/chardev/char.h
include/qemu/option.h
ui/console-vc.c
util/qemu-option.c

index 48b326d57b9acfd6d587ee12c13241a8b13abab1..55dce9725e8bb4f27976e80e3f2d123a8539caa9 100644 (file)
@@ -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;
 
index c2c42e4b7a32d1d1c4084dbb12917ef97bfe00a2..51995f06a8242b4235d7acf3d8ba24aaa28213ab 100644 (file)
@@ -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);
index 01e673ae03f076708a7ec040f42a9f889dd05032..9a00ac0a3561a27e131eb1685538c007f08df285 100644 (file)
@@ -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
index 6163e21d2c6a9474a900991600bed5fe10bef348..62a5e3caf57e3c4ae54c378d98647a0670b7d078 100644 (file)
@@ -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 = {
index 770300dff12d786889f9fdd7d9494ce4a9d191d7..9fbf425f86e06e5f2a2f0a5878aefccb5940275c 100644 (file)
@@ -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;