From nobody Mon Apr 29 01:30:32 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=1628773793; cv=none; d=zohomail.com; s=zohoarc; b=VOXGjeWkRiD26tHZZs/x9JVGPDcLZ0AWThYr4Qi7KEx7az/JNEM85uG1bTS8wRgHeOUZutRgDRVZ17ArFAWNCeNanR1zujcvHiF3ApZsSEoDupgzG7RBjL81Qg6o1R9RPzdVXMas6ix0k8xekTiYvnqM3ywO1yjKztPP39dz3AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773793; 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=NTGkhtIVN69DC1owHCueg54Vt//twesadE07fQKqnOU=; b=OhRbGKRmJkyNfqtbBJ1qh2GARifBpUQ78FTv4sSNdL2ZeySpTMf35ABcX7mcmyavRAX+xp7WqhKokxm19yW4Ut/i8FGIyaOOtgqwfO1uz5OOJpSqhtQhqSVR3U6xudSJZ29SH6YtnmcMfczWPfNM30mPh83IV/VAZkAfMem0r34= 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) 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 1628773793144465.2529477594053; Thu, 12 Aug 2021 06:09:53 -0700 (PDT) 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-479-zKFT3g3eMC-xG0nX8mVSbQ-1; Thu, 12 Aug 2021 09:09:50 -0400 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 4C83A10766C7; Thu, 12 Aug 2021 13:09:44 +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 849876A914; Thu, 12 Aug 2021 13:09:42 +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 A9A134A7C8; Thu, 12 Aug 2021 13:09:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1ha4029722 for ; Thu, 12 Aug 2021 09:01:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D5935D9DE; Thu, 12 Aug 2021 13:01:43 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72F3F5D9C6 for ; Thu, 12 Aug 2021 13:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773792; 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=NTGkhtIVN69DC1owHCueg54Vt//twesadE07fQKqnOU=; b=K/eoLOyzCodxtBzC+aIRTxsLmzQzBoim1WVioLNCZS0j42eL5s4f32xLisOEVja6zJOCpS /LHhDi9ntqhV56DhcDnm1cysumRHZHyZdWanCciXQLDhK/kVzXGJ3nSat9bFLxjD0ifbSG AoiE9XcS9htABMLNQSgplr0kW8gbGwQ= X-MC-Unique: zKFT3g3eMC-xG0nX8mVSbQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] virsh: Un-document 'virsh echo' Date: Thu, 12 Aug 2021 15:01:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1628773794011100003 Content-Type: text/plain; charset="utf-8" Note that it's for internal testing use and remove the manpage entry. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/manpages/virsh.rst | 17 ----------------- tools/vsh.c | 4 ++-- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 20936994ce..4075929a76 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -907,23 +907,6 @@ print that all CPU models are accepted for these archi= tectures and the actual list of supported CPU models can be checked in the domain capabilities XML. -echo ----- - -**Syntax:** - -:: - - echo [--shell] [--xml] [err...] [arg...] - -Echo back each *arg*, separated by space. If *--shell* is -specified, then the output will be single-quoted where needed, so that -it is suitable for reuse in a shell context. If *--xml* is -specified, then the output will be escaped for use in XML. -If *--err* is specified, prefix ``"error: "`` and output to stderr -instead of stdout. - - hypervisor-cpu-compare ---------------------- diff --git a/tools/vsh.c b/tools/vsh.c index f9600bafba..f44db5d56d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3139,10 +3139,10 @@ const vshCmdOptDef opts_echo[] =3D { const vshCmdInfo info_echo[] =3D { {.name =3D "help", - .data =3D N_("echo arguments") + .data =3D N_("echo arguments. Used for internal testing.") }, {.name =3D "desc", - .data =3D N_("Echo back arguments, possibly with quoting.") + .data =3D N_("Echo back arguments, possibly with quoting. Used for in= ternal testing.") }, {.name =3D NULL} }; --=20 2.31.1 From nobody Mon Apr 29 01:30:32 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=1628773925; cv=none; d=zohomail.com; s=zohoarc; b=GSCtZg7xpnzzPKazj1NVu4z6k0ffd9RpkbVjlvu2YD7g3h5BiXcGk8K23WMXBnXMo2wN3Jmjur4DsuHLgQjAa6cOVjLFtP5nNrvU+p5YdnJoTrQeSBuKuoVIpQh7qk/RPUY1ug649Ckiid4ZGnm4s88SO/JMIu6W9pxdzUxDu+k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773925; 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=X9u8AgLx5TVn873b+QFqHcFBrvNpiteRMntG+3nq5zA=; b=HUu1mHwdi2fMsPIKSxTYvPMymuQ39Vy/Nfxjp6gfgpui5aqJ7PCJ6y+piNkpDesAGRQltcUweedPPDTuWJ/oV5cpJtUXOma1Y7EXSoPQTMbeYuOVBoNshS6tStrLBHkkQlv4gRwAYk9AGjj6P1AEkfqmDBku7YwaXc9PKJMhO0E= 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) 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 1628773925766615.3658542231377; Thu, 12 Aug 2021 06:12:05 -0700 (PDT) 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-145-vn_K_BbRO72x_Wd6osrcuA-1; Thu, 12 Aug 2021 09:12:02 -0400 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 3AC52802CB7; Thu, 12 Aug 2021 13:11:03 +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 1F6E36F97F; Thu, 12 Aug 2021 13:11:03 +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 DE2B14A700; Thu, 12 Aug 2021 13:11:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1io1029730 for ; Thu, 12 Aug 2021 09:01:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FD925DA61; Thu, 12 Aug 2021 13:01:44 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 810DA5D9C6 for ; Thu, 12 Aug 2021 13:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773924; 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=X9u8AgLx5TVn873b+QFqHcFBrvNpiteRMntG+3nq5zA=; b=A6orv11ae5lbAsD7fdfWLSt7P2vpciokh22ulpGYByRsN41zKiQ+CUY4+vhaHpUWvlC1FD Wpcl6HExkLws9cOFNGtgOgjC86RmM0UkY7HYE9vjAeit1SzICBDgdT8U8hANqvF2PyarU+ yTaaiisO8gUf1zDiXw0UCCF5QcMDeKI= X-MC-Unique: vn_K_BbRO72x_Wd6osrcuA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] virshtest: Don't use both '--xml' and '--shell' for 'virsh echo' Date: Thu, 12 Aug 2021 15:01:32 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1628773926388100001 Content-Type: text/plain; charset="utf-8" Escaping for both shell and XML makes no sense. Use one at time so that we can forbid use of both. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virshtest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 53db2aa19a..07c27428ae 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -432,9 +432,8 @@ mymain(void) DO_TEST(15, "a A 0 + * ; . ' " / ? =3D \n < > &\= n", "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "=3D", " ", "\n", "<", ">", "&"); - DO_TEST(16, "a A 0 + '*' ';' . ''' '"' / '?' =3D ' ' '\n' '&= lt;'" - " '>' '&'\n", - "echo", "--shell", "--xml", "a", "A", "0", "+", "*", ";", ".",= "'", + DO_TEST(16, "a A 0 + '*' ';' . ''\\''' '\"' / '?' =3D ' ' '\n' '<' '>'= '&'\n", + "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "\'", "\"", "/", "?", "=3D", " ", "\n", "<", ">", "&"); DO_TEST(17, "\n", "echo", ""); @@ -443,7 +442,7 @@ mymain(void) DO_TEST(19, "\n", "echo", "--xml", ""); DO_TEST(20, "''\n", - "echo", "--xml", "--shell", ""); + "echo", "--shell", ""); DO_TEST(21, "\n", "echo ''"); DO_TEST(22, "''\n", @@ -451,7 +450,7 @@ mymain(void) DO_TEST(23, "\n", "echo --xml ''"); DO_TEST(24, "''\n", - "echo --xml --shell \"\"''"); + "echo --shell \"\"''"); /* Tests of -- handling. */ DO_TEST(25, "a\n", --=20 2.31.1 From nobody Mon Apr 29 01:30:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1628773841; cv=none; d=zohomail.com; s=zohoarc; b=bUhV/O3qIwiNfX485np+ozssp4K8K4Kt5Sdb9br33KJD0u787SU4OEH+ZHPJ0O8Su6HgH5t8ePJ+L7MC6jRlOlTQ/PZ+Oukvhq4dEJdkMSc1QTQqdJncXA0ar9Xgu0O7hmRfVsDJak6JZVBRZXy4iP+Q/f7HU2O5eUFMT/7rAPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773841; 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=6aApM9NcFfUJhUSLGpWN17KQKOlCPXRUb6Z39VskkXY=; b=bHNT4Y0X8wRIoWa0ywSPh7NIGgenufT4YHawbCBxxyfwYvGYpRlAUYwsObdUxWHdvGc/5QLDmV0fnWVfl/oHh+RfgtZFrinIbMn9UGusVoPB2SXmSL876fuP1/ot/BtK3ziyBs/5MfSgneeDKLYwTDsLtXCupXlfpk7OsqJHJSM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628773841375362.42252917089377; Thu, 12 Aug 2021 06:10:41 -0700 (PDT) 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-58-q4vUs_3oNQiEdLUATsiwZw-1; Thu, 12 Aug 2021 09:10:38 -0400 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 39152106B397; Thu, 12 Aug 2021 13:10:21 +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 03F018462C; Thu, 12 Aug 2021 13:10:21 +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 A847C181A100; Thu, 12 Aug 2021 13:10:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1j1X029735 for ; Thu, 12 Aug 2021 09:01:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 467025DA61; Thu, 12 Aug 2021 13:01:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id A620F5D9C6 for ; Thu, 12 Aug 2021 13:01:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773840; 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=6aApM9NcFfUJhUSLGpWN17KQKOlCPXRUb6Z39VskkXY=; b=PIm+ToYcrd0s5rAe6cJXgpuQbNpicugcPkcBj4U6Qgaizu2C5E69A60dYHnf93FQ56Wvr4 Lyzds1W2h2HqWK9VIhbtVahfYGXu7rKY8P3AuQYopuar5kQl6FTqbmdrJnSWVOc5LY3TO2 VgzXyDdYKtcbh4Aq3AstzXZMNmQuC8w= X-MC-Unique: q4vUs_3oNQiEdLUATsiwZw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/6] virsh: cmdEcho: Make '--xml' and '--shell' mutually exclusive Date: Thu, 12 Aug 2021 15:01:33 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1628773841780100001 Content-Type: text/plain; charset="utf-8" Initialize the flags earlier and use VSH_EXCLUSIVE_OPTIONS_VAR to declare the conflicting options as exclusive. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index f44db5d56d..009c93254c 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3153,20 +3153,15 @@ const vshCmdInfo info_echo[] =3D { bool cmdEcho(vshControl *ctl, const vshCmd *cmd) { - bool shell =3D false; - bool xml =3D false; - bool err =3D false; + bool shell =3D vshCommandOptBool(cmd, "shell"); + bool xml =3D vshCommandOptBool(cmd, "xml"); + bool err =3D vshCommandOptBool(cmd, "err"); int count =3D 0; const vshCmdOpt *opt =3D NULL; g_autofree char *arg =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - if (vshCommandOptBool(cmd, "shell")) - shell =3D true; - if (vshCommandOptBool(cmd, "xml")) - xml =3D true; - if (vshCommandOptBool(cmd, "err")) - err =3D true; + VSH_EXCLUSIVE_OPTIONS_VAR(shell, xml); while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { g_autofree char *str =3D NULL; --=20 2.31.1 From nobody Mon Apr 29 01:30:32 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=1628773806; cv=none; d=zohomail.com; s=zohoarc; b=AtkWR6i40+XVQKMt8I/ggkzvgZ5s4Bm7AhmpaatEpTLitJtteWynN6kjXX6lv0RLzK266poinrOJ5Y9oveY+CpshGIgJCldSioO1UxeObnpPFM83y1RLVQ0mMAQA4LZsVmrrXz8kxoY+sPuwxJsLMKMiMViyAIigAaaZPmdCUM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773806; 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=QoDzu9gEaJeqksrN3Z4DdRcTAsBRxBQzvjdRJ6WJIiU=; b=I0fE8UCQfcQic2ygsnZ3CdTaJn8C7L+xX831gI6a3U74VM25y15CqWSghe/FdDpW+NFA59ZSjWggmitaUrYd3tCu4v1PQaMQg40oSkEvI0MpqlztxzGvDcg+4rxmK/jY2w9n4QIaWD5TIWs7rwh+XDlZ8dJeVSY1lW/JQBzlDK0= 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) 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 1628773806183629.671064655617; Thu, 12 Aug 2021 06:10:06 -0700 (PDT) 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-553-8EnC9C7SNI-1T4irP1qZ9w-1; Thu, 12 Aug 2021 09:10:03 -0400 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 2158F107B78F; Thu, 12 Aug 2021 13:09:58 +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 06AB18464A; Thu, 12 Aug 2021 13:09:58 +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 39D92181A0F2; Thu, 12 Aug 2021 13:09:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1k4b029740 for ; Thu, 12 Aug 2021 09:01:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5BA1C5DA61; Thu, 12 Aug 2021 13:01:46 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id B26F25D9C6 for ; Thu, 12 Aug 2021 13:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773805; 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=QoDzu9gEaJeqksrN3Z4DdRcTAsBRxBQzvjdRJ6WJIiU=; b=jSeRm/AcBhNV/LFNzBpzrxtPp5u5oMo0LF/eNtzcpJfe3r4sYLTORdJb+NlMTgarC08ody wNGsJYszLPLrbQF9drQbmOPwPvWANHqprL+Sb1cvxp6g5WBAC4Y7ebyAXjQssunFkaUel+ 9I6vtODNjHFjoob3/Z6K7BlStIOz2Rg= X-MC-Unique: 8EnC9C7SNI-1T4irP1qZ9w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/6] virsh: cmdEcho: Rewrite with new buffer helpers Date: Thu, 12 Aug 2021 15:01:34 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1628773806675100001 Content-Type: text/plain; charset="utf-8" Remove the need for temporary strings by fillin the output buffer directly. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 009c93254c..2456267426 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3156,7 +3156,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) bool shell =3D vshCommandOptBool(cmd, "shell"); bool xml =3D vshCommandOptBool(cmd, "xml"); bool err =3D vshCommandOptBool(cmd, "err"); - int count =3D 0; const vshCmdOpt *opt =3D NULL; g_autofree char *arg =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; @@ -3164,27 +3163,21 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(shell, xml); while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { - g_autofree char *str =3D NULL; - g_auto(virBuffer) xmlbuf =3D VIR_BUFFER_INITIALIZER; const char *curr =3D opt->data; - if (count) - virBufferAddChar(&buf, ' '); - if (xml) { - virBufferEscapeString(&xmlbuf, "%s", curr); - str =3D virBufferContentAndReset(&xmlbuf); + virBufferEscapeString(&buf, "%s", curr); + } else if (shell) { + virBufferEscapeShell(&buf, curr); } else { - str =3D g_strdup(curr); + virBufferAdd(&buf, curr, -1); } - if (shell) - virBufferEscapeShell(&buf, str); - else - virBufferAdd(&buf, str, -1); - count++; + virBufferAddChar(&buf, ' '); } + virBufferTrim(&buf, " "); + arg =3D virBufferContentAndReset(&buf); if (arg) { if (err) --=20 2.31.1 From nobody Mon Apr 29 01:30:32 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=1628773947; cv=none; d=zohomail.com; s=zohoarc; b=G3BcdMxHMJAwAznzYJeaago/MTwGH4eGYHcUINGJVRwNHk43YxjBUfxPRzsxAF3oXVstvXPUUCQz1E7bRUYHddwGuWKIyLNkJc10IZVpYtkEhkVp8AMof01Mn6hzOvjz7xLc+XipE6t4BSBjKyirs1iyuDgX7sgNnFS1dH56WtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773947; 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=Dp8ODgYC66q0kPWiROg6rag0UG7WGnCE61oMgRa1wcw=; b=Pq8sLg/g50ORL39nVg8Tp3CSKxDem9q2IF18oQGOMngNKy1SpQ0XCGV5uWrhKoCiXUOr5T0GkYTKS936DXOvqo+PV14utoDruoZqwPqQ9l2ARFWWDdIe5hYgcDFVj/LIPtEJHjfAMfXtoWjnCmrrcWeYi/77tdtbJPwZG2zljOI= 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) 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 1628773947569828.4539166744132; Thu, 12 Aug 2021 06:12:27 -0700 (PDT) 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-557-sClPyxo3PPKj7ELbojpmcA-1; Thu, 12 Aug 2021 09:12:25 -0400 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 3B22310B1E85; Thu, 12 Aug 2021 13:11:07 +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 17F935D9C6; Thu, 12 Aug 2021 13:11:07 +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 DA101181A137; Thu, 12 Aug 2021 13:11:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1l4q029745 for ; Thu, 12 Aug 2021 09:01:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C8F75DA61; Thu, 12 Aug 2021 13:01:47 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id C79AA5D9C6 for ; Thu, 12 Aug 2021 13:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773946; 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=Dp8ODgYC66q0kPWiROg6rag0UG7WGnCE61oMgRa1wcw=; b=Y3xq0ScWkiljeMiw2Q13xhgRoYUEKG2j2IopHnWTmWO8aQmSVYauN94v7hikgio3seuBdW fn56Uefcua9XN2Uxxrhw8vtLalVkZZwmOfoxcE7d+GL0beZgr+i0SLdrUYYx2nNFzU/BlR J0mY/XNW44IsdoB7FrrVAFrTuTx2YlA= X-MC-Unique: sClPyxo3PPKj7ELbojpmcA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] virsh: Add testing for vshStringToArray Date: Thu, 12 Aug 2021 15:01:35 +0200 Message-Id: <7d209edda66215ac28c55d4e796d55e4e8b1d33a.1628773245.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1628773948843100001 Content-Type: text/plain; charset="utf-8" Add a '--split' switch for the 'virsh echo' command and add few test cases to the virshtest. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virshtest.c | 11 +++++++++++ tools/vsh.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/virshtest.c b/tests/virshtest.c index 07c27428ae..751e8ffc49 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -487,6 +487,17 @@ mymain(void) DO_TEST(46, "a\n", "#unbalanced; 'quotes\"\necho a # b"); DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); + /* test of splitting in vshStringToArray */ + DO_TEST(48, "a\nb,c,\nd,,e,,\nf,,,e\n", + "-q", "echo", "--split", "a,b,,c,,,d,,,,e,,,,,f,,,,,,e"); + DO_TEST(49, "\na\nb,c,\nd,,e,,\nf,,,e\n\n", + "-q", "echo", "--split", ",a,b,,c,,,d,,,,e,,,,,f,,,,,,e,"); + DO_TEST(50, ",a\nb,c,\nd,,e,,\nf,,,e,\n", + "-q", "echo", "--split", ",,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,"); + DO_TEST(51, ",\na\nb,c,\nd,,e,,\nf,,,e,\n\n", + "-q", "echo", "--split", ",,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,"); + DO_TEST(52, ",,a\nb,c,\nd,,e,,\nf,,,e,,\n", + "-q", "echo", "--split", ",,,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,,= "); # undef DO_TEST VIR_FREE(custom_uri); diff --git a/tools/vsh.c b/tools/vsh.c index 2456267426..cdcf67684e 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3118,6 +3118,10 @@ const vshCmdOptDef opts_echo[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("escape for XML use") }, + {.name =3D "split", + .type =3D VSH_OT_BOOL, + .help =3D N_("split each argument on ','; ',,' is an escape sequence") + }, {.name =3D "err", .type =3D VSH_OT_BOOL, .help =3D N_("output to stderr"), @@ -3156,11 +3160,14 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) bool shell =3D vshCommandOptBool(cmd, "shell"); bool xml =3D vshCommandOptBool(cmd, "xml"); bool err =3D vshCommandOptBool(cmd, "err"); + bool split =3D vshCommandOptBool(cmd, "split"); const vshCmdOpt *opt =3D NULL; g_autofree char *arg =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; VSH_EXCLUSIVE_OPTIONS_VAR(shell, xml); + VSH_EXCLUSIVE_OPTIONS_VAR(shell, split); + VSH_EXCLUSIVE_OPTIONS_VAR(xml, split); while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { const char *curr =3D opt->data; @@ -3169,6 +3176,14 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) virBufferEscapeString(&buf, "%s", curr); } else if (shell) { virBufferEscapeShell(&buf, curr); + } else if (split) { + g_auto(GStrv) spl =3D NULL; + GStrv n; + + vshStringToArray(curr, &spl); + + for (n =3D spl; *n; n++) + virBufferAsprintf(&buf, "%s\n", *n); } else { virBufferAdd(&buf, curr, -1); } --=20 2.31.1 From nobody Mon Apr 29 01:30:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1628773854; cv=none; d=zohomail.com; s=zohoarc; b=n7jIgDd3shNroyKd3zuERcnzIjOBOHERQJeOJslWQOs3uoG06v+4QCJGPqod4BnDRcsknguquF26jvLzJcDev9JGUAKHLS5qTjLQjv3iuO4fGKtfe+p8hyMPqSr4VrjY30kWFXfdsONepVmVczZFOH6Ap/VNl4iUr4ngP+kEkkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773854; 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=5VeH65NLE1H6QdY16tVYcd479jmRWB5Dx/ALTuRMeTo=; b=hU7fmDSwjUDCtMpyR3MWO/GH2aVkpDH76NncZLiDiblYpzaWSRlYr5IIbX4rRamRY8HTaFeDcJQwPRD5btKGOzo9VsSieSbFnhCePROV7NNlCzckhnKzIHXFJpX5ZRE0ZL7TJwREJemQc9Gabg2Fi6Q31V7F/bpChsgSgI1MPY4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628773854133251.96776453004884; Thu, 12 Aug 2021 06:10:54 -0700 (PDT) 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-148-5RGB8yuYMxWhVe4JboEMow-1; Thu, 12 Aug 2021 09:10:51 -0400 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 EA6738ED9FE; Thu, 12 Aug 2021 13:10:25 +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 98C2C6CA26; Thu, 12 Aug 2021 13:10:24 +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 4D2D54A700; Thu, 12 Aug 2021 13:10:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1mRi029750 for ; Thu, 12 Aug 2021 09:01:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 785875D9DE; Thu, 12 Aug 2021 13:01:48 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF7BC5D9C6 for ; Thu, 12 Aug 2021 13:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773853; 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=5VeH65NLE1H6QdY16tVYcd479jmRWB5Dx/ALTuRMeTo=; b=cwdo5iTLV7NzHImqxIBc1/yrv7I1OBR87qyucUZs5TbMsaJ4e3KtH6V3uTuX7U1wdvOPSV M0y39SNWvEKcYnycpr+SA6zpPmkB2vLtNFFFG9i6A+xG0OmFN2Yoc2icduNlYMB4PJGyrU pHA3swYLggiC3wRy2P/QiNBc5V2eYec= X-MC-Unique: 5RGB8yuYMxWhVe4JboEMow-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] vshStringToArray: Rewrite using 'g_strsplit' Date: Thu, 12 Aug 2021 15:01:36 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1628773854923100001 Content-Type: text/plain; charset="utf-8" Use 'g_strsplit' to split the strings and then concatenate back when the escape sequence (',,') is used. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 62 ++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index cdcf67684e..202a507f2e 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -122,48 +122,38 @@ int vshStringToArray(const char *str, char ***array) { - g_autofree char *str_copied =3D g_strdup(str); - char *str_tok =3D NULL; - char *tmp; - unsigned int nstr_tokens =3D 0; - char **arr =3D NULL; - size_t len =3D strlen(str_copied); - - /* tokenize the string from user and save its parts into an array */ - nstr_tokens =3D 1; - - /* count the delimiters, recognizing ,, as an escape for a - * literal comma */ - str_tok =3D str_copied; - while ((str_tok =3D strchr(str_tok, ','))) { - if (str_tok[1] =3D=3D ',') - str_tok++; - else - nstr_tokens++; - str_tok++; - } + g_auto(GStrv) tmp =3D NULL; + GStrv n; + size_t ntoks =3D 0; + bool concat =3D false; + + tmp =3D g_strsplit(str, ",", 0); + + *array =3D g_new0(char *, g_strv_length(tmp) + 1); + (*array)[ntoks++] =3D g_strdup(tmp[0]); - /* reserve the NULL element at the end */ - arr =3D g_new0(char *, nstr_tokens + 1); + /* undo splitting of comma escape (',,') by concatenating back on empt= y strings */ + for (n =3D tmp + 1; n[0]; n++) { + if (concat) { + g_autofree char *old =3D (*array)[ntoks - 1]; - /* tokenize the input string, while treating ,, as a literal comma */ - nstr_tokens =3D 0; - tmp =3D str_tok =3D str_copied; - while ((tmp =3D strchr(tmp, ','))) { - if (tmp[1] =3D=3D ',') { - memmove(&tmp[1], &tmp[2], len - (tmp - str_copied) - 2 + 1); - len--; - tmp++; + (*array)[ntoks - 1] =3D g_strconcat(old, ",", n[0], NULL); + concat =3D false; continue; } - *tmp++ =3D '\0'; - arr[nstr_tokens++] =3D g_strdup(str_tok); - str_tok =3D tmp; + + if (strlen(n[0]) =3D=3D 0) { + concat =3D true; + } else { + (*array)[ntoks++] =3D g_strdup(n[0]); + } } - arr[nstr_tokens++] =3D g_strdup(str_tok); - *array =3D arr; - return nstr_tokens; + /* corner case of ending with a single comma */ + if (concat) + (*array)[ntoks++] =3D g_strdup(""); + + return ntoks; } virErrorPtr last_error; --=20 2.31.1