From nobody Sat May 30 15:29:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1779975290; cv=none; d=zohomail.com; s=zohoarc; b=dCuCLGxFj5tVeYjz6mf9480vd7LGgz7UpT9DKRWtH5p3VSHcMm7tn0zIf/lALUoI+T8zkdzjqEzm+fQqT7hodquTH8uFddx9wpvdhfD8378Ck8tyQadnpbogXRrg/mCYhNclyQDzK3AZDG4gGJz3VgFI+3xPoDbwNmmDP1iS+QY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779975290; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=JoCrLSEShp5Bu45DBvOTKzUB2QTMxXLAnT/d+rqZPsM=; b=PRGlN6Ub67zMPXS1Ld6uCAWwX316eYHq7YSdx2oT0dcStM8KwJPQ9YMmJTis2So9PJwbIoBsXGY4vpgbpK1f6wx1Jfp/T04vBXFV8s/ojYI17ZhP2RWvb9rHcuBeOZCJ7bN1vemOzYYUOArZwGRH5TikVfse6evp2tkUevgs0po= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1779975290306642.3229627093701; Thu, 28 May 2026 06:34:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B053A41B3F; Thu, 28 May 2026 09:34:49 -0400 (EDT) Received: from [172.19.199.5] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 29C6B41E1D; Thu, 28 May 2026 09:30:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 36AA841ABA; Thu, 28 May 2026 09:28:47 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 883CC41A40 for ; Thu, 28 May 2026 09:28:45 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-8b_2swtXMh2xkaZNG0msUg-1; Thu, 28 May 2026 09:28:43 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AA97D1944D25 for ; Thu, 28 May 2026 13:28:35 +0000 (UTC) Received: from dhora-thinkpadp1gen4i.tpbc.csb (unknown [10.43.3.17]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0A04219560A3 for ; Thu, 28 May 2026 13:28:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779974925; h=from:from: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; bh=JoCrLSEShp5Bu45DBvOTKzUB2QTMxXLAnT/d+rqZPsM=; b=NniFPilYZasI4HWWhTViFYVGsB5pQMYPOyIiWM0yj8A6YAADu6cxwqO2uZrxp3xLb6sdS7 UPWedjBB78mPRgef3rTkJ93DetkDmvMVip8m1xo6EAP/RB1rQIkuhsnc0gevl/ghnKsQhZ +8FwEIzZeLf3GJRT1okwjqt25mKkops= X-MC-Unique: 8b_2swtXMh2xkaZNG0msUg-1 X-Mimecast-MFC-AGG-ID: 8b_2swtXMh2xkaZNG0msUg_1779974922 To: devel@lists.libvirt.org Subject: [PATCH] examples: Improved shell output of showDomains Date: Thu, 28 May 2026 15:28:26 +0200 Message-ID: <78ce74fa97cb7420d3dca5d36e646af17f4b8132.1779974906.git.dhora@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: EkxBM6JDUGG_p1jN6JYoIKPpGEdnWSBm_5Q2DXjQSME_1779974922 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-MailFrom: dhora@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation Message-ID-Hash: GKO2ATOKYEGZW3TFCITJPSL4Y3453EB3 X-Message-ID-Hash: GKO2ATOKYEGZW3TFCITJPSL4Y3453EB3 X-Mailman-Approved-At: Thu, 28 May 2026 13:30:22 +0000 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Daniel Hora via Devel Reply-To: Daniel Hora X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1779975292657154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Daniel Hora Improved formatting of the shell output of the function showDomains based on length of the longest domain. Signed-off-by: Daniel Hora Reviewed-by: Michal Privoznik --- examples/c/misc/hellolibvirt.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/examples/c/misc/hellolibvirt.c b/examples/c/misc/hellolibvirt.c index 39cefe934c..77098d7be3 100644 --- a/examples/c/misc/hellolibvirt.c +++ b/examples/c/misc/hellolibvirt.c @@ -4,6 +4,7 @@ =20 #include #include +#include #include #include =20 @@ -44,11 +45,34 @@ showHypervisorInfo(virConnectPtr conn) return 0; } =20 +static int +longestDomain(virDomainPtr *nameList, int numNames) +{ + int longestDomainLength; + size_t i; + + longestDomainLength =3D 0; + + for (i =3D 0; i < numNames; i++) { + const char *currentDomain =3D virDomainGetName(nameList[i]); + + if (currentDomain !=3D NULL) { + int currentDomainLength =3D strlen(currentDomain); + + if (currentDomainLength > longestDomainLength) { + longestDomainLength =3D currentDomainLength; + } + } + } + + return longestDomainLength; + +} =20 static int showDomains(virConnectPtr conn) { - int numNames, numInactiveDomains, numActiveDomains; + int numNames, numInactiveDomains, numActiveDomains, longestDomainLengt= h; ssize_t i; int flags =3D VIR_CONNECT_LIST_DOMAINS_ACTIVE | VIR_CONNECT_LIST_DOMAINS_INACTIVE; @@ -88,9 +112,12 @@ showDomains(virConnectPtr conn) return 1; } =20 + longestDomainLength =3D longestDomain(nameList, numNames); + for (i =3D 0; i < numNames; i++) { int active =3D virDomainIsActive(nameList[i]); - printf(" %8s (%s)\n", + printf(" %-*s (%s)\n", + longestDomainLength, virDomainGetName(nameList[i]), (active =3D=3D 1 ? "active" : "non-active")); /* must free the returned named per the API documentation */ --=20 2.54.0