From nobody Mon Feb 9 05:20:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1491926074321360.7803938120709; Tue, 11 Apr 2017 08:54:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 04B008FCEE; Tue, 11 Apr 2017 15:54:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF96B18ED9; Tue, 11 Apr 2017 15:54: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 5F6965EC6B; Tue, 11 Apr 2017 15:54:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3BFsAXx001682 for ; Tue, 11 Apr 2017 11:54:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id A65C37ED8A; Tue, 11 Apr 2017 15:54:10 +0000 (UTC) Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 454917ED8E; Tue, 11 Apr 2017 15:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 04B008FCEE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 04B008FCEE From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:55 +0200 Message-Id: <615a25f076b1523934775c59c5029f741791d33b.1491925946.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 9/9] virsh-domain: Refactor cmdTTYConsole 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 11 Apr 2017 15:54:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the new XML helpers and use virXPathString rather than hand-rolling the code. --- tools/virsh-domain.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d64a2dca0..d6f33b1ee 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11183,37 +11183,23 @@ static bool cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml =3D NULL; - xmlXPathObjectPtr obj =3D NULL; xmlXPathContextPtr ctxt =3D NULL; - virDomainPtr dom; bool ret =3D false; - char *doc; + char *tty =3D NULL; - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) return false; - doc =3D virDomainGetXMLDesc(dom, 0); - if (!doc) + if (!(tty =3D virXPathString("string(/domain/devices/console/@tty)", c= txt))) goto cleanup; - xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt); - VIR_FREE(doc); - if (!xml) - goto cleanup; - - obj =3D xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", = ctxt); - if (obj =3D=3D NULL || obj->type !=3D XPATH_STRING || - obj->stringval =3D=3D NULL || obj->stringval[0] =3D=3D 0) { - goto cleanup; - } - vshPrint(ctl, "%s\n", (const char *)obj->stringval); + vshPrint(ctl, "%s\n", tty); ret =3D true; cleanup: - xmlXPathFreeObject(obj); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virshDomainFree(dom); + VIR_FREE(tty); return ret; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list