From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667664; cv=none; d=zohomail.com; s=zohoarc; b=WLNx84Bx2It19caX/beOP64y+XAgbElhTrDKXZedQf4rwZ7XAG0J468PbwaoZb/4kJeg6Ic/Vexq3DfZI/17os7nRGRbIDJpPCGmAMa8AahtD3Z2T0gvdcrXWlGpXtLHFBqrgD6yIWol4Px2Ql0Ap9ttxcw/L9dNAQoZQmydUko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667664; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FGRKP+VAHJh9Q9q648MuZzZuG5RtZ8zUml4TZmTodHA=; b=MkFEfhe5IurbVA8Yo3FH4R1Lp3ziy0mnAfO73y/uOEX9RPqv4G9dZQ2etRJZS8UNgEJgs7pomGmkCyH2I24YmurUYj07owAJuDiKtoyUKtOsk3te7VjevVptiP+aWcADnltk1D5HucrAIYgrNNgM2yOZVJPeimSiItfqu61c5X4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611667664546909.4339983228847; Tue, 26 Jan 2021 05:27:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-501-4gMGLmuZPhWuAdfrg9Ffqg-1; Tue, 26 Jan 2021 08:27:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BBA73802B42; Tue, 26 Jan 2021 13:27:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97D0E5C26D; Tue, 26 Jan 2021 13:27:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 806B04BB7B; Tue, 26 Jan 2021 13:27:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRKPS001328 for ; Tue, 26 Jan 2021 08:27:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F4A91880F; Tue, 26 Jan 2021 13:27:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id A11455C276 for ; Tue, 26 Jan 2021 13:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667663; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FGRKP+VAHJh9Q9q648MuZzZuG5RtZ8zUml4TZmTodHA=; b=Iv1MX53UfYGqJ2FeKYtWsaXHXzPzhDVCpJRusPMgha73MPELtK4xDlWMgiuTjiPgHxFjUr BVnLSCDlJhEzptaMtBavBcbpCVA41xxy0z6P7JWPokW50GrkaMCSYlq/7S/c9ensQ6ixCa HNrSFBFwV8WUsFPWBXRf1ToKA7HsYHQ= X-MC-Unique: 4gMGLmuZPhWuAdfrg9Ffqg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/9] vshCommandStringGetArg: Drop @sz Date: Tue, 26 Jan 2021 14:27:05 +0100 Message-Id: <110bc230982f0c0638e55888a55ae3a2aff62d55.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This variable is unused since introduction of the function in v0.8.5~150. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index badd37c08e..54253afa72 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1608,7 +1608,6 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPar= ser *parser, char **res, { bool single_quote =3D false; bool double_quote =3D false; - int sz =3D 0; char *p =3D parser->pos; char *q =3D g_strdup(p); =20 @@ -1662,7 +1661,6 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPar= ser *parser, char **res, } =20 *q++ =3D *p++; - sz++; } if (double_quote) { if (report) --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667884; cv=none; d=zohomail.com; s=zohoarc; b=XliWjDIHEGLVcmTCqydfg5B1jI4AFc5qoqJYNtp456Vkh1QtjHW2gP614I8Eg7IBBc5riwJgnzKjQesqQHNa24ByjerO3wGtgttr2iwJ7V7xUFvou2SsULj0GVWm2j4KUX9nf6uCQxTxiNqdijO/ftJjSaxR5EMm8J3ZHUrkR08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667884; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1HCkr+QDsG1j8QDCWhWRp7i3iVgjvfZQUg72kKAvztw=; b=R8M2UPhmklUkFHl0SlEBukxfyBUGW847sUMbatjulsR2oeM43Z1uew3sFX/6VP4O3Gz0C/NDjvv9YGgQkMnwwmvKaEG+JkdFakLjb37MeB2DxCslbES8Jbh/UnDZkLLhoo37Mq/dtILy3wN26oSNJP8g4cf52XzKDvNbZrPNStc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611667884125689.4306095210834; Tue, 26 Jan 2021 05:31:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-G8yZXtLnPDGomlxh48dgcA-1; Tue, 26 Jan 2021 08:31:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A67010054FF; Tue, 26 Jan 2021 13:31:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 174315D719; Tue, 26 Jan 2021 13:31:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D23164BB7B; Tue, 26 Jan 2021 13:31:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDROa3001344 for ; Tue, 26 Jan 2021 08:27:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F7C45C276; Tue, 26 Jan 2021 13:27:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3B1A63743 for ; Tue, 26 Jan 2021 13:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667883; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1HCkr+QDsG1j8QDCWhWRp7i3iVgjvfZQUg72kKAvztw=; b=cKZDnPO3athSMJG+Xwkrpn0VUENJbfqOrjzWdqhgVE5OxS4KT4mcFe30JRah8pgtesCnk6 eGITXKElY64bEqlTtBcWgRjOVUI/I7OF6hfXqyfV3qsOoXylXaMeaPuSZzw5//+i3yZ+Yn LQVB5GkOijKp9dX94Z2R+HccfYBcjLY= X-MC-Unique: G8yZXtLnPDGomlxh48dgcA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/9] vsh: Don't break word on backslash Date: Tue, 26 Jan 2021 14:27:06 +0100 Message-Id: <25789a1f9e9d103a5db217bea66c3e45015fac3a.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" A backslash is the way we escape characters in virsh. For instance: virsh # start domain\ with\ long\ name For readline completion, we do not want to get four separate words ("domain", "with", "long", "name"). This means, that we can't sue virBufferEscapeShell() because it doesn't escape spaces the way we want. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 54253afa72..9856088126 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2773,7 +2773,7 @@ vshReadlineParse(const char *text, int state) if (ret && !rl_completion_quote_character) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - virBufferEscapeShell(&buf, ret); + virBufferEscape(&buf, '\\', " ", "%s", ret); VIR_FREE(ret); ret =3D virBufferContentAndReset(&buf); } @@ -2819,7 +2819,7 @@ vshReadlineInit(vshControl *ctl) int ret =3D -1; char *histsize_env =3D NULL; const char *histsize_str =3D NULL; - const char *break_characters =3D " \t\n\\`@$><=3D;|&{("; + const char *break_characters =3D " \t\n`@$><=3D;|&{("; const char *quote_characters =3D "\"'"; =20 /* Opaque data for autocomplete callbacks. */ --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667762; cv=none; d=zohomail.com; s=zohoarc; b=HZeSLvL1zEUzxwjaEStiSh32fRwB8/T+WE8HMbFFIpIVgKCzwqhVTJI1ztcHYVqjMWD7uF+9zJDRnTQdTndpSesWaC7R95Pqi4f7/+hnGcbYuKG9hnwEcyvdhtAvWZOcC8k20nhgiXvJ8fJFJ3B1rEuG9yqI1PdgOgjdGwS6S+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667762; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=epfxPHHBbjexCRT74GAJwT7+b4PKdA3cOib3QlTBBvI=; b=Vxd0veaidl8WRCDH4kK2dq85iq2JOXolUiCCt4LNXPQWPgqwC/4toWajptVIQavkhAvupW12uVkCGNqqMonYJw5LZzmnM+KN317CB3dUZfYnCcGzahDrn+jGKVyGTXpfLnOBhnTz9wv8KpW3Lf2H+LQqfQ5EsS3lTQgKSfo5taI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611667762096704.5744841931433; Tue, 26 Jan 2021 05:29:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-nbF20hb5MmWCmxbFtL-k2Q-1; Tue, 26 Jan 2021 08:27:46 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6B22801AB6; Tue, 26 Jan 2021 13:27:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5AF360CCE; Tue, 26 Jan 2021 13:27:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6FA5E1809CA0; Tue, 26 Jan 2021 13:27:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRPj9001351 for ; Tue, 26 Jan 2021 08:27:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1EFD11880F; Tue, 26 Jan 2021 13:27:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92CB85C276 for ; Tue, 26 Jan 2021 13:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667761; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=epfxPHHBbjexCRT74GAJwT7+b4PKdA3cOib3QlTBBvI=; b=gojsMNZjsKUBBKGZt1ev1TTyqOqhyDDt7bmYSW5FAdIQ2k5+iS1HKcte/KFCkpbX4bhs5j uUOrh2dW1dAZ0v1zQ9Uqv7v9koKVMcUiEKBhbR5MnhPpfC9bhoRz59EMMqybvDn2YHOlvA ssL6/quvpD0TdYQndHT6ZT6AKUQ1xw8= X-MC-Unique: nbF20hb5MmWCmxbFtL-k2Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/9] vshReadlineParse: Bring some variables into !state block Date: Tue, 26 Jan 2021 14:27:07 +0100 Message-Id: <908ebac3ce28221f76d57617bf322862379d4ca3.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" On readline completion vshReadlineCompletion() is called which does nothing more than calling rl_completion_matches() with vshReadlineParse() as a callback. This means, that vshReadlineParse() is called repeatedly, each time returning next completion candidate, until it returns NULL which is interpreted as the end of the list of candidates. The function takes two parameters: @text which is a portion of input line around cursor when TAB was pressed, and @state. The @state is an integer that is zero on the very first call and non-zero on each subsequent call (in fact, readline does @state++ on each call). Anyway, the idea is that the callback gets the whole list of candidates on @state =3D=3D 0 and returns one candidate at each call. And this is what vshReadlineParse() is doing but some variables (@parital, @cmd and @opt) are really used only in the @state =3D=3D 0 case but declared for whole function. We can limit their scope by declaring them inside the @state =3D=3D 0 body which also means that they don't have to be static anymore. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 9856088126..ba6299aae4 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2695,18 +2695,20 @@ vshCompleterFilter(char ***list, static char * vshReadlineParse(const char *text, int state) { - static vshCmd *partial; static char **list; static size_t list_index; - const vshCmdDef *cmd =3D NULL; - const vshCmdOptDef *opt =3D NULL; char *ret =3D NULL; =20 + /* Readline calls this function until NULL is returned. On + * the very first call @state is zero which means we should + * initialize those static variables above. On subsequent + * calls @state is non zero. */ if (!state) { + vshCmd *partial =3D NULL; + const vshCmdDef *cmd =3D NULL; + const vshCmdOptDef *opt =3D NULL; char *buf =3D g_strdup(rl_line_buffer); =20 - vshCommandFree(partial); - partial =3D NULL; g_strfreev(list); list =3D NULL; list_index =3D 0; @@ -2734,9 +2736,7 @@ vshReadlineParse(const char *text, int state) } =20 opt =3D vshReadlineCommandFindOpt(partial, text); - } =20 - if (!list) { if (!cmd) { list =3D vshReadlineCommandGenerator(text); } else { @@ -2759,10 +2759,12 @@ vshReadlineParse(const char *text, int state) (vshCompleterFilter(&completer_list, text) < 0 || virStringListMerge(&list, &completer_list) < 0)) { g_strfreev(completer_list); + vshCommandFree(partial); goto cleanup; } } } + vshCommandFree(partial); } =20 if (list) { @@ -2780,15 +2782,12 @@ vshReadlineParse(const char *text, int state) =20 cleanup: if (!ret) { - vshCommandFree(partial); - partial =3D NULL; g_strfreev(list); list =3D NULL; list_index =3D 0; } =20 return ret; - } =20 static char ** --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667670; cv=none; d=zohomail.com; s=zohoarc; b=ebGzhK4e4orfxptfyKpgf6Oa0uI0lQnNcl4picjVb/e8y+O1iVklfOt18izxW08tnmGmjzBxzYaZ1ci8JYhf1zm6kRCFOBsmac7mh33cqu5TZ6qzaOY/gvKeqFnBcNM8tEf90c1m4AqHtgPy09QGneHwxMOVRiONBmZIg1kKor4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667670; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1s0lhd7PeSkupsOKPmM0KXdecsdC926gW7+hAtEDmAE=; b=TMJphDHRLZbYvWdCbbPu9qKxGLkywusmMphoQWcuIuvTQjuiop2FM7BE9AFCLE/Vh3GqN56MiO3khqWR00fq5yo2DNFwtVmF2XtBMyV+Otq9vH/3APzb4alQ7lFheByL7CikhqCx9x/3iGreReH4TwhSyCOJ4YAFNL0BV4IOwcs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 161166767060156.64591745772043; Tue, 26 Jan 2021 05:27:50 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-502-gRZwgM6iMX-S_Xep1K1OuQ-1; Tue, 26 Jan 2021 08:27:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B397F8015D4; Tue, 26 Jan 2021 13:27:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D9B75FC29; Tue, 26 Jan 2021 13:27:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4E5305002F; Tue, 26 Jan 2021 13:27:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRPSL001359 for ; Tue, 26 Jan 2021 08:27:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id F0A455C276; Tue, 26 Jan 2021 13:27:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 722C55C73F for ; Tue, 26 Jan 2021 13:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667669; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1s0lhd7PeSkupsOKPmM0KXdecsdC926gW7+hAtEDmAE=; b=a3GZdBT4oPItTPVpkJgEHecayA4e+x4OY8GKUmPgWa+3D7Ord3MEEcPNm8i0MW+j9Y4779 WdT0nY4BfDRzsZHPcR+pIaZkO+INB5IApP0ETNTF5Exe63wOLqHnl/nLsbFydZJ8aJBfwP vp6GykgeJ2YLb0cawMlUOBN+zs0mrwo= X-MC-Unique: gRZwgM6iMX-S_Xep1K1OuQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/9] vshReadlineParse: Use g_auto*() Date: Tue, 26 Jan 2021 14:27:08 +0100 Message-Id: <6af704f87f4de9a4b11a87385409b1406594d475.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Instead of freeing @partial and @buf explicitly, we can use g_auto*() to do that automatically. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index ba6299aae4..9a7ca6776b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -739,6 +739,8 @@ vshCommandFree(vshCmd *cmd) } } =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(vshCmd, vshCommandFree); + /** * vshCommandOpt: * @cmd: parsed command line to search @@ -2704,10 +2706,10 @@ vshReadlineParse(const char *text, int state) * initialize those static variables above. On subsequent * calls @state is non zero. */ if (!state) { - vshCmd *partial =3D NULL; + g_autoptr(vshCmd) partial =3D NULL; const vshCmdDef *cmd =3D NULL; const vshCmdOptDef *opt =3D NULL; - char *buf =3D g_strdup(rl_line_buffer); + g_autofree char *buf =3D g_strdup(rl_line_buffer); =20 g_strfreev(list); list =3D NULL; @@ -2717,8 +2719,6 @@ vshReadlineParse(const char *text, int state) =20 vshCommandStringParse(NULL, buf, &partial); =20 - VIR_FREE(buf); - if (partial) { cmd =3D partial->def; partial->skipChecks =3D true; @@ -2759,12 +2759,10 @@ vshReadlineParse(const char *text, int state) (vshCompleterFilter(&completer_list, text) < 0 || virStringListMerge(&list, &completer_list) < 0)) { g_strfreev(completer_list); - vshCommandFree(partial); goto cleanup; } } } - vshCommandFree(partial); } =20 if (list) { --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667743; cv=none; d=zohomail.com; s=zohoarc; b=GssCH4buTB0GwFuI4+JGuVtieriCz4GeXDhlRpRW3owRtnlQQG1bRVQXKRjDgWInguIpCeMBcfKJ8hh8qGE5iXOgrI7S97WTGqIF5yJpPgNVLhLEW+Py2lfE7KCzB6mznWHkmM9mXRiMHFBZngeaPfIbe4tWdcR1B82Wzq3TU+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667743; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oOfC+7QSCk3L8SU2UoPI0ucjU/Idxphdkcef24Shoa4=; b=CTuYlNEHf1JHt6ZVkS7kEkLklCReCgOPnPGjs1uBRBrs0KkhvfOrkRpVF3r/F1j8kEnqcwyYuxPBwiF8C/0qJx6SEknwzDK7Svyj88L0TrBXULae6YbljQYdDAaRkFPfEVzkFlCLE+pcvkaPlZmFoOuWSCAqZf+LmS019tbECrI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611667743872556.9848153385955; Tue, 26 Jan 2021 05:29:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-gliMQLtSO1iySkbMJU0IbQ-1; Tue, 26 Jan 2021 08:27:49 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F3958030AE; Tue, 26 Jan 2021 13:27:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 49D0C10016FB; Tue, 26 Jan 2021 13:27:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 14B0750033; Tue, 26 Jan 2021 13:27:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRQ4V001373 for ; Tue, 26 Jan 2021 08:27:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id CC3BE1880F; Tue, 26 Jan 2021 13:27:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E2235C276 for ; Tue, 26 Jan 2021 13:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667742; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oOfC+7QSCk3L8SU2UoPI0ucjU/Idxphdkcef24Shoa4=; b=HCgia/YbPubHErGRnoPfKVBPWKbPgs9m3yhtcHpJN3X8kT4wNeu25AnBf02ogHpNv2MWs5 r3BScb86iz0915zF7m0DwWJFSHpt0XbslGYcBMWLdIcJHMTvejkv+s3JJnlPI7OB+ckc8F pWMKsCf/H+Bmp24q574MaP5J+SG9rFw= X-MC-Unique: gliMQLtSO1iySkbMJU0IbQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/9] vshReadlineParse: Rename @buf to @line Date: Tue, 26 Jan 2021 14:27:09 +0100 Message-Id: <4f2f2e2119e2a5f4f89af6ca75190a9f0de4bf89.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In next commit the block that does escaping of returned string will be brought into this block. But both contain variable @buf and use it in different contexts. Rename @buf from @state =3D=3D 0 block to @line which reflects its purpose better. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 9a7ca6776b..abbd323e24 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2709,15 +2709,15 @@ vshReadlineParse(const char *text, int state) g_autoptr(vshCmd) partial =3D NULL; const vshCmdDef *cmd =3D NULL; const vshCmdOptDef *opt =3D NULL; - g_autofree char *buf =3D g_strdup(rl_line_buffer); + g_autofree char *line =3D g_strdup(rl_line_buffer); =20 g_strfreev(list); list =3D NULL; list_index =3D 0; =20 - *(buf + rl_point) =3D '\0'; + *(line + rl_point) =3D '\0'; =20 - vshCommandStringParse(NULL, buf, &partial); + vshCommandStringParse(NULL, line, &partial); =20 if (partial) { cmd =3D partial->def; --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667890; cv=none; d=zohomail.com; s=zohoarc; b=lQtlc3RYpNT0a4Z/EaAJYJM15KXQRFUTC4akrBFDRePXUl6RkyS0S0+Vwb50aCk1FcRmLwbBlSP2shyLjM4KyZ8p6ka3Z4RsiRWTebopbVW3iH5EkYaE1UrtKpb0DartxeP0myCBXEDPcOfGVagw82yqeIDIeuc0kktGQwrqt14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667890; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q9ATFvR+FJevq2WswQM/BMBoU+1XjIh/g/tU/TzWQQU=; b=JHaixduE3og4Kxla0AKWc/Lpu4BGUpydfAJ7886mES4ScA/27RHJ04pnEM6jR8a9s4OqaOcnvOid/Etg+gP/GztR/oSsFl766yKxMQ+mOqSQzcmYT9o2AXUTreely3D0jPV73SvUk6IT58azOhT9vkyo5JjI5DEkfDqFFI+xceY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 161166789084331.044055689487777; Tue, 26 Jan 2021 05:31:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-117-j1tTW3J_Py6QaMKExv6tTw-1; Tue, 26 Jan 2021 08:31:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBF58100C605; Tue, 26 Jan 2021 13:31:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B51D05D9C2; Tue, 26 Jan 2021 13:31:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 77A6D4EBC6; Tue, 26 Jan 2021 13:31:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRUu6001398 for ; Tue, 26 Jan 2021 08:27:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id E74A75C26D; Tue, 26 Jan 2021 13:27:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68B9774AA0 for ; Tue, 26 Jan 2021 13:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667889; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Q9ATFvR+FJevq2WswQM/BMBoU+1XjIh/g/tU/TzWQQU=; b=c0GlTXuw2Q3djF8IlYFJbtCL2xkmBDNUQ9anDwbDYDcXQbr09q3YmSn/O1ev+HVYpp7ddE e+0jIUntMzmLn3w88QXwPR4l/LI7Mi+u8IaGElhplcvJTR/0MAjz0OcfAl08TeI0ozfL4Q jsDrQqRxsL1/YeqdwscsLtwe1fs9M40= X-MC-Unique: j1tTW3J_Py6QaMKExv6tTw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/9] vshReadlineParse: Escape list of candidates earlier Date: Tue, 26 Jan 2021 14:27:10 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The way our completer callbacks work is that they return all possible candidates and then vshCompleterFilter() is called to prune the list of all candidates removing those which don't match user's input. This allows us to have simpler completer callbacks as their only job is to fetch all possible candidates. Anyway, if the completion candidate we're returning contains a space, it has to be escaped (shell like escaping), unless there is already a quote character (single quote or double quote). But ordering is critical. Completer callback returns string without any escaping, but the filter function sees the user input escaped. For instance, if user's input is "domain with space" then the filtering function gets "domain\ with\ space" as user's input but completer returns "domain with space". Since these two strings don't match the filtering function removes this candidate from the list. What we need to do is to escape strings before calling the filtering function. This way, the filtering function will see two same strings. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index abbd323e24..27c201389d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2751,10 +2751,26 @@ vshReadlineParse(const char *text, int state) partial, opt->completer_flag= s); =20 + /* Escape completions, if needed (i.e. argument + * we completing wasn't started with a quote + * character). This also enables filtering done + * below to work properly. */ + if (completer_list && + !rl_completion_quote_character) { + size_t i; + + for (i =3D 0; completer_list[i]; i++) { + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferEscape(&buf, '\\', " ", "%s", completer_l= ist[i]); + VIR_FREE(completer_list[i]); + completer_list[i] =3D virBufferContentAndReset(&bu= f); + } + } + /* For string list returned by completer we have to do * filtering based on @text because completer returns all * possible strings. */ - if (completer_list && (vshCompleterFilter(&completer_list, text) < 0 || virStringListMerge(&list, &completer_list) < 0)) { @@ -2770,14 +2786,6 @@ vshReadlineParse(const char *text, int state) list_index++; } =20 - if (ret && - !rl_completion_quote_character) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - virBufferEscape(&buf, '\\', " ", "%s", ret); - VIR_FREE(ret); - ret =3D virBufferContentAndReset(&buf); - } - cleanup: if (!ret) { g_strfreev(list); --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667661; cv=none; d=zohomail.com; s=zohoarc; b=J6DwwVN9F4llpzGPXt40qScZJ56bRQpUE0S+btNNzr0lGcLebn0ISOenujzeRIGzzAyj2yjaUKH+yw3JCM7BkQO3kS0KlhGUFwM8ONYsWg/KNpMwx9bKYKOwd6E2sb/O7aF8KB0rSIixc/pGclm4ISKmHIbp4HuWPsyp/iOaVPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667661; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rTk2BlpZwwCd2kADzbwX3vCiwiADrxqWmwS9NQitDts=; b=gDXVs46lXfoc9Fe53NGSOma/xBVhEhbX0kWNw6T7uISiz8dqS3BtCGlMPTgSljTxzSjtBqkXoAWPOe3A9rbV1wh7My7B+FXxZGdVt7lStdx+GlKKtcOdp8Gw6K+i5okhZsY3tlKEHI3q/IM0uIWYxpaqkkUJ083ghmpC4BXQTdk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611667661114427.9086563484908; Tue, 26 Jan 2021 05:27:41 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-QeDa2eaIMFS9C3WpXcU8RQ-1; Tue, 26 Jan 2021 08:27:38 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8D501005D4E; Tue, 26 Jan 2021 13:27:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0F2710013BD; Tue, 26 Jan 2021 13:27:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 56AC51809CA2; Tue, 26 Jan 2021 13:27:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRV4L001405 for ; Tue, 26 Jan 2021 08:27:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id C4AF01880F; Tue, 26 Jan 2021 13:27:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 458735C26D for ; Tue, 26 Jan 2021 13:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667660; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rTk2BlpZwwCd2kADzbwX3vCiwiADrxqWmwS9NQitDts=; b=a0dssvcWxgDRSU3nCXWJKgXeDHhzUWEQHJ5fQhoA/71WfyKek+BJbalH2ztaY9l9HSZxpK LT3txnuIUOX+z7ei+SBuOddC7dAk23aeuVsEd+DEw9HdEibiT9GrNyLx0uk1xByc4e8WZz Xs7s4jApGQtEfz8HVsNZCJsX7qcy5pI= X-MC-Unique: QeDa2eaIMFS9C3WpXcU8RQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 7/9] vsh: Rework how option to complete is found Date: Tue, 26 Jan 2021 14:27:11 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The way that auto completion works currently is that user's input is parsed, and then we try to find the first --option (in the parsed structure) that has the same value as user's input around where was pressed. For instance, for the following input: virsh # command --arg1 hello --arg2 world we will see "world" as text that user is trying to autocomplete (this is affected by rl_basic_word_break_characters which readline uses internally to break user's input into individual words) and find that it is --arg2 that user is trying to autocomplete. So far so good, for this naive approach. But consider the following example: virsh # command --arg1 world --arg2 world Here, both arguments have the same value and because we see "world" as text that user is trying to autocomplete we would think that it is --arg1 that user wants to autocomplete. This is obviously wrong. Fortunately, readline stores the current position of cursor (into rl_point) and we can use that when parsing user's input: whenever we reach a position that matches the cursor then we know that that is the place where was pressed and hence that is the --option that user wants to autocomplete. Readline stores the cursor position as offset (numbered from 1) from the beginning of user's input. We store this input into @parser->pos initially, but then advance it as we tokenize it. Therefore, what we need is to store the original position too. Thanks to Martin who helped me with this. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/virsh.c | 4 ++-- tools/virt-admin.c | 4 ++-- tools/vsh.c | 58 ++++++++++++++++++++++++++++++++-------------- tools/vsh.h | 5 +++- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index a6bfbbbb87..732655a894 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -777,7 +777,7 @@ virshParseArgv(vshControl *ctl, int argc, char **argv) ctl->imode =3D false; if (argc - optind =3D=3D 1) { vshDebug(ctl, VSH_ERR_INFO, "commands: \"%s\"\n", argv[optind]= ); - return vshCommandStringParse(ctl, argv[optind], NULL); + return vshCommandStringParse(ctl, argv[optind], NULL, 0); } else { return vshCommandArgvParse(ctl, argc - optind, argv + optind); } @@ -915,7 +915,7 @@ main(int argc, char **argv) if (*ctl->cmdstr) { vshReadlineHistoryAdd(ctl->cmdstr); =20 - if (vshCommandStringParse(ctl, ctl->cmdstr, NULL)) + if (vshCommandStringParse(ctl, ctl->cmdstr, NULL, 0)) vshCommandRun(ctl, ctl->cmd); } VIR_FREE(ctl->cmdstr); diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 72084a78e9..1108a07896 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1364,7 +1364,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **arg= v) ctl->imode =3D false; if (argc - optind =3D=3D 1) { vshDebug(ctl, VSH_ERR_INFO, "commands: \"%s\"\n", argv[optind]= ); - return vshCommandStringParse(ctl, argv[optind], NULL); + return vshCommandStringParse(ctl, argv[optind], NULL, 0); } else { return vshCommandArgvParse(ctl, argc - optind, argv + optind); } @@ -1594,7 +1594,7 @@ main(int argc, char **argv) if (*ctl->cmdstr) { vshReadlineHistoryAdd(ctl->cmdstr); =20 - if (vshCommandStringParse(ctl, ctl->cmdstr, NULL)) + if (vshCommandStringParse(ctl, ctl->cmdstr, NULL, 0)) vshCommandRun(ctl, ctl->cmd); } VIR_FREE(ctl->cmdstr); diff --git a/tools/vsh.c b/tools/vsh.c index 27c201389d..e5c6cebebb 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1318,6 +1318,8 @@ struct _vshCommandParser { char **, bool); /* vshCommandStringGetArg() */ char *pos; + const char *originalLine; + size_t point; /* vshCommandArgvGetArg() */ char **arg_pos; char **arg_end; @@ -1426,6 +1428,10 @@ vshCommandParse(vshControl *ctl, vshCommandParser *p= arser, vshCmd **partial) arg->data =3D tkdata; tkdata =3D NULL; arg->next =3D NULL; + + if (parser->pos - parser->originalLine =3D=3D = parser->point - 1) + arg->completeThis =3D true; + if (!first) first =3D arg; if (last) @@ -1477,6 +1483,9 @@ vshCommandParse(vshControl *ctl, vshCommandParser *pa= rser, vshCmd **partial) arg->next =3D NULL; tkdata =3D NULL; =20 + if (parser->pos - parser->originalLine =3D=3D parser->poin= t) + arg->completeThis =3D true; + if (!first) first =3D arg; if (last) @@ -1588,7 +1597,7 @@ vshCommandArgvGetArg(vshControl *ctl G_GNUC_UNUSED, bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv) { - vshCommandParser parser; + vshCommandParser parser =3D { 0 }; =20 if (nargs <=3D 0) return false; @@ -1675,15 +1684,38 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandP= arser *parser, char **res, return VSH_TK_ARG; } =20 + +/** + * vshCommandStringParse: + * @ctl virsh control structure + * @cmdstr: string to parse + * @partial: store partially parsed command here + * @point: position of cursor (rl_point) + * + * Parse given string @cmdstr as a command and store it under + * @ctl->cmd. For readline completion, if @partial is not NULL on + * the input then errors in parsing are ignored (because user is + * still in progress of writing the command string) and partially + * parsed command is stored at *@partial (caller has to free it + * afterwards). Among with @partial, caller must set @point which + * is the position of cursor in @cmdstr (offset, numbered from 1). + * Parser will then set @completeThis attribute to true for the + * vshCmdOpt that appeared under the cursor. + */ bool -vshCommandStringParse(vshControl *ctl, char *cmdstr, vshCmd **partial) +vshCommandStringParse(vshControl *ctl, + char *cmdstr, + vshCmd **partial, + size_t point) { - vshCommandParser parser; + vshCommandParser parser =3D { 0 }; =20 if (cmdstr =3D=3D NULL || *cmdstr =3D=3D '\0') return false; =20 parser.pos =3D cmdstr; + parser.originalLine =3D cmdstr; + parser.point =3D point; parser.getNextArg =3D vshCommandStringGetArg; return vshCommandParse(ctl, &parser, partial); } @@ -2634,28 +2666,20 @@ vshReadlineOptionsGenerator(const char *text, =20 =20 static const vshCmdOptDef * -vshReadlineCommandFindOpt(const vshCmd *partial, - const char *text) +vshReadlineCommandFindOpt(const vshCmd *partial) { const vshCmd *tmp =3D partial; =20 - while (tmp && tmp->next) { - if (tmp->def =3D=3D tmp->next->def && - !tmp->next->opts) - break; - tmp =3D tmp->next; - } - - if (tmp && tmp->opts) { + while (tmp) { const vshCmdOpt *opt =3D tmp->opts; =20 while (opt) { - if (STREQ_NULLABLE(opt->data, text) || - STREQ_NULLABLE(opt->data, " ")) + if (opt->completeThis) return opt->def; =20 opt =3D opt->next; } + tmp =3D tmp->next; } =20 return NULL; @@ -2717,7 +2741,7 @@ vshReadlineParse(const char *text, int state) =20 *(line + rl_point) =3D '\0'; =20 - vshCommandStringParse(NULL, line, &partial); + vshCommandStringParse(NULL, line, &partial, rl_point); =20 if (partial) { cmd =3D partial->def; @@ -2735,7 +2759,7 @@ vshReadlineParse(const char *text, int state) cmd =3D NULL; } =20 - opt =3D vshReadlineCommandFindOpt(partial, text); + opt =3D vshReadlineCommandFindOpt(partial); =20 if (!cmd) { list =3D vshReadlineCommandGenerator(text); diff --git a/tools/vsh.h b/tools/vsh.h index 0c5584891d..39f70913fe 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -152,6 +152,8 @@ struct _vshCmdOptDef { struct _vshCmdOpt { const vshCmdOptDef *def; /* non-NULL pointer to option definition */ char *data; /* allocated data, or NULL for bool option= */ + bool completeThis; /* true if this is the option user's wishi= ng to + autocomplete */ vshCmdOpt *next; }; =20 @@ -292,7 +294,8 @@ int vshBlockJobOptionBandwidth(vshControl *ctl, unsigned long *bandwidth); bool vshCommandOptBool(const vshCmd *cmd, const char *name); bool vshCommandRun(vshControl *ctl, const vshCmd *cmd); -bool vshCommandStringParse(vshControl *ctl, char *cmdstr, vshCmd **partial= ); +bool vshCommandStringParse(vshControl *ctl, char *cmdstr, + vshCmd **partial, size_t point); =20 const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd, const vshCmdOpt *opt); --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667743; cv=none; d=zohomail.com; s=zohoarc; b=Q+BRxCC3AUsnSUzX2YBofj8XNoxl34I3Bu4iSTJdrzC7NZLaTNlNCJ5/zcFWN/c5MWJL0XR0aSPI16FEH6MFZSStUZua6tEFMryW7WAB9/qNEAV/Dd2prSj6ZikL1QDPI31aVZx9haJkPz6bGTT7+ooH8LckXJiTspFkhglR6sI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667743; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MW4F0MaxxqtKbiu2M8CRtmP4D71VMkWLu6Q+w7Xiz9I=; b=W5vXSYDPWXTYmqVJF8pS1axf/o4gQcSCyQfpMVZam6kvr+wrlntDMqbRJfpmrg6jI8jFW3ujyUqp+PkOaLHveYuzOcebAdY3M6LmuAgIcmPCbIm1oqHbaWWuGbvBOflW52KZwdtNW9kLvyIlumH0FpVV64Gl97xP3m4XGQxgn44= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611667743868318.0534279946975; Tue, 26 Jan 2021 05:29:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-u4BkGRf0MjGhH0MkWD1v2Q-1; Tue, 26 Jan 2021 08:27:43 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 719C2107ACF9; Tue, 26 Jan 2021 13:27:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5046A5D9E2; Tue, 26 Jan 2021 13:27:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0E0FD5002D; Tue, 26 Jan 2021 13:27:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRW4Z001413 for ; Tue, 26 Jan 2021 08:27:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9E8B25C26D; Tue, 26 Jan 2021 13:27:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 209D15C73F for ; Tue, 26 Jan 2021 13:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667742; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=MW4F0MaxxqtKbiu2M8CRtmP4D71VMkWLu6Q+w7Xiz9I=; b=fGddLht9eYT8oPDd5qjurn0qZP25QbKDys0v3SxWXBcLcDtAzPbxZLx4jwa/H9AMJO8Ah3 Ch5xWd1NovmSNFtDgByrvfx1ySvDLK6Y+OFMIFpmPcriOoUP/M8yq5fIcdePOP6yHuVC4w LIrWs7Uk/h99cy7aKDZpUlNcKbEV7CY= X-MC-Unique: u4BkGRf0MjGhH0MkWD1v2Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 8/9] vsh: Allow double quotes imbalance for auto completion in vshCommandStringGetArg() Date: Tue, 26 Jan 2021 14:27:12 +0100 Message-Id: <17994097b94b3e07001302c84c2c77ec6b71d722.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" If user is trying to auto complete a value that contains a space, they have two options: use backslash to escape space or use qotes, like this: virsh # start --domain "domain with space However, in this case our tokenizer sees imbalance in (double) quotes: there is a starting one that's missing it's companion. Well, that's obvious - user is still in process of writing the command. What we need to do in this case is to ignore the imbalance and return success (from the tokenizer) - readline will handle closing the quote properly. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index e5c6cebebb..53a84b9d95 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1418,7 +1418,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *pa= rser, vshCmd **partial) if (optstr) tkdata =3D optstr; else - tk =3D parser->getNextArg(ctl, parser, &tkdata, tr= ue); + tk =3D parser->getNextArg(ctl, parser, &tkdata, pa= rtial =3D=3D NULL); if (tk =3D=3D VSH_TK_ERROR) goto syntaxError; if (tk !=3D VSH_TK_ARG) { @@ -1673,10 +1673,16 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandP= arser *parser, char **res, =20 *q++ =3D *p++; } + if (double_quote) { - if (report) + /* We have seen a double quote, but not it's companion + * ending. It's valid though, in case when we're called + * from completer (report =3D false), but it's not valid + * when parsing real command (report=3D true). */ + if (report) { vshError(ctl, "%s", _("missing \"")); - return VSH_TK_ERROR; + return VSH_TK_ERROR; + } } =20 *q =3D '\0'; --=20 2.26.2 From nobody Fri May 3 14:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611667894; cv=none; d=zohomail.com; s=zohoarc; b=HX6eJPLSyid8cl80pP9tCrx49yGMsHiEtlBmcwlTXRaun2rRvQ14VAVYDT7KJYlrLBCoQlTLJHcDqOxUF8r8gZErf8jFFS9hmV19PeLH/BEv2MkYsyVchTyoB9+9cGcPY0AgQ7/itdXYl7Y1iIHnK5anccijeTaE1kmSQPTFwCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611667894; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=W595L1s68NyoKT+J1wZ3nHNgXBz+uVe3A3dUQTkIsNI=; b=mXUdNYTcYEIn4uRu7ulvDYXUk16GRP1H+3cKCIMQFKHm/qFTXJQJdeKcMi7KaBIoLi8bNLdfvbLT2ssrPYKdg0zFls5SP5Rri61LCoTBqzWZDRmtW7jJbxLODylVNJBbqT+YLl1a3W2wfJ7TYMlbhtFPpDDMWfCIhvq/hY8TExU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611667894928162.3180156116698; Tue, 26 Jan 2021 05:31:34 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-9kCIbbs0O8qFn69TsGJw7A-1; Tue, 26 Jan 2021 08:31:30 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7CE310054FF; Tue, 26 Jan 2021 13:31:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83E491F0; Tue, 26 Jan 2021 13:31:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4C348180954D; Tue, 26 Jan 2021 13:31:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10QDRXcE001423 for ; Tue, 26 Jan 2021 08:27:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 794A01880F; Tue, 26 Jan 2021 13:27:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFA505C26D for ; Tue, 26 Jan 2021 13:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611667893; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=W595L1s68NyoKT+J1wZ3nHNgXBz+uVe3A3dUQTkIsNI=; b=Iwa6yLSI8GnSeCT5TVMtxnoNJqOzsvMMeJ4F9b7Sl93QAL0oeWQfxc1O7Qnrz1Cj79rMvP wn7DFShe3Lk+4SNdZr5DPoyAZxgdi05oaBhWsBMSv1lU82jaFfj1qKZwAdYhTjaayDWGLT ++a3iotuObJprL4dss1H8Uxjk7wxHK0= X-MC-Unique: 9kCIbbs0O8qFn69TsGJw7A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 9/9] tools: Set IFS for bash completion script Date: Tue, 26 Jan 2021 14:27:13 +0100 Message-Id: <7257869328326f1aa42f239f9f1163480b487c7d.1611667532.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The way our bash completion string is that is gets user's input and lets virsh completion code do all the work by calling 'virsh complete -- $INPUT". The 'complete' command is a "secret", unlisted command that exists solely for this purpose. After it has done it's part, it prints candidates onto stdout, each candidate on its own line, e.g. like this: # virsh complete -- "net-u" net-undefine net-update net-uuid These strings are then stored into a bash array $A like this: A=3D($($1 ${CMDLINE} complete -- "${INPUT[@]}" 2>/dev/null)) This array is then thrown back at bash completion to produce desired output. So far so good. Except, when there is an option with space. For instance: # virsh complete -- start --domain "" uefi\ duplicate uefi Bash interprets that as another array item because by default, Internal Field Separator (IFS) =3D set of characters that bash uses to split words at, is: space, TAB, newline. We don't want space nor TAB. Therefore, we have to set $IFS when storing 'virsh complete' output into the array. Thanks to Peter who suggested it. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/116 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/bash-completion/vsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bash-completion/vsh b/tools/bash-completion/vsh index fb38e8616f..bbb25fc3eb 100644 --- a/tools/bash-completion/vsh +++ b/tools/bash-completion/vsh @@ -56,7 +56,7 @@ _vsh_complete() # the name of the command whose arguments are being # completed. # Therefore, we might just run $1. - A=3D($($1 ${CMDLINE} complete -- "${INPUT[@]}" 2>/dev/null)) + IFS=3D$'\n' A=3D($($1 ${CMDLINE} complete -- "${INPUT[@]}" 2>/dev/null= )) =20 COMPREPLY=3D($(compgen -W "${A[*]%--}" -- ${cur})) __ltrim_colon_completions "$cur" --=20 2.26.2