From nobody Tue Feb 10 12:42:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634739226103361.45742912211847; Wed, 20 Oct 2021 07:13:46 -0700 (PDT) Received: from localhost ([::1]:48710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdCLh-0001Yb-5Y for importer@patchew.org; Wed, 20 Oct 2021 10:13:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdC3s-000795-BQ for qemu-devel@nongnu.org; Wed, 20 Oct 2021 09:55:20 -0400 Received: from proxmox-new.maurer-it.com ([94.136.29.106]:32577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdC3o-0006uA-Ow for qemu-devel@nongnu.org; Wed, 20 Oct 2021 09:55:19 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7B4314691F; Wed, 20 Oct 2021 15:55:13 +0200 (CEST) From: Stefan Reiter To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Dr. David Alan Gilbert" , Markus Armbruster , Paolo Bonzini , Eric Blake , Gerd Hoffmann , Wolfgang Bumiller , Thomas Lamprecht Subject: [PATCH v6 1/5] monitor/hmp: add support for flag argument with value Date: Wed, 20 Oct 2021 15:54:56 +0200 Message-Id: <20211020135500.2384930-2-s.reiter@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211020135500.2384930-1-s.reiter@proxmox.com> References: <20211020135500.2384930-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=94.136.29.106; envelope-from=s.reiter@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1634739228186100001 Content-Type: text/plain; charset="utf-8" Adds support for the "-xV" parameter type, where "-x" denotes a flag name and the "V" suffix indicates that this flag is supposed to take an arbitrary string parameter. These parameters are always optional, the entry in the qdict will be omitted if the flag is not given. Signed-off-by: Stefan Reiter Reviewed-by: Eric Blake --- v6: It wasn't possible to pass the 'connected' parameter to set_password, since= the code to handle optional parameters couldn't live with a different param (not starting with '-') coming up instead - fix that by advancing over the 'value flag' modifier in case `*p !=3D '-'`. Also change the modifier to 'V' instead of 'S' so it can be distinguished f= rom an actual trailing 'S' type param. Discovered in testing. I dropped Eric's R-b due to the code change. monitor/hmp.c | 19 ++++++++++++++++++- monitor/monitor-internal.h | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index d50c3124e1..899e0c990f 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -980,6 +980,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, { const char *tmp =3D p; int skip_key =3D 0; + int ret; /* option */ =20 c =3D *typestr++; @@ -1002,11 +1003,27 @@ static QDict *monitor_parse_arguments(Monitor *mon, } if (skip_key) { p =3D tmp; + } else if (*typestr =3D=3D 'V') { + /* has option with string value */ + typestr++; + tmp =3D p++; + while (qemu_isspace(*p)) { + p++; + } + ret =3D get_str(buf, sizeof(buf), &p); + if (ret < 0) { + monitor_printf(mon, "%s: value expected for -%= c\n", + cmd->name, *tmp); + goto fail; + } + qdict_put_str(qdict, key, buf); } else { - /* has option */ + /* has boolean option */ p++; qdict_put_bool(qdict, key, true); } + } else if (*typestr =3D=3D 'V') { + typestr++; } } break; diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 9c3a09cb01..9e708b329d 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -63,7 +63,8 @@ * '.' other form of optional type (for 'i' and 'l') * 'b' boolean * user mode accepts "on" or "off" - * '-' optional parameter (eg. '-f') + * '-' optional parameter (eg. '-f'); if followed by an 'V', it + * specifies an optional string param (e.g. '-fV' allows '-f = foo') * */ =20 --=20 2.30.2