From mboxrd@z Thu Jan 1 00:00:00 1970 From: Osier Yang Subject: Re: [PATCH] kvm tools: Beautify kvm list output Date: Wed, 26 Oct 2011 14:13:37 +0800 Message-ID: <4EA7A511.40600@redhat.com> References: <1319611381-27164-1-git-send-email-jyang@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: QUOTED-PRINTABLE To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35633 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750894Ab1JZGNj (ORCPT ); Wed, 26 Oct 2011 02:13:39 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9Q6DcEg027741 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 Oct 2011 02:13:39 -0400 Received: from [10.3.238.241] (vpn-238-241.phx2.redhat.com [10.3.238.241]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9Q6Dbqc025983 for ; Wed, 26 Oct 2011 02:13:38 -0400 In-Reply-To: <1319611381-27164-1-git-send-email-jyang@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: =D3=DA 2011=C4=EA10=D4=C226=C8=D5 14:43, Osier Yang =D0=B4=B5=C0: > With the patch, output of "kvm list" will be: > > % ./kvm list > PID NAME STATE > ------------------------------------ > 5270 test running > test shut off > default shut off > > "not running" is changed into "shut off", as it might > be other states which are "not running" in future? such > as "paused". > > Signed-off-by: Osier Yang > --- > tools/kvm/builtin-list.c | 10 +++++++--- > 1 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c > index 2ff3472..4cabd59 100644 > --- a/tools/kvm/builtin-list.c > +++ b/tools/kvm/builtin-list.c > @@ -33,6 +33,9 @@ static const struct option list_options[] =3D { > OPT_END() > }; > =20 > +#define KVM_INSTANCE_RUNNING "running" > +#define KVM_INSTANCE_SHUTOFF "shut off" > + > void kvm_list_help(void) > { > usage_with_options(list_usage, list_options); > @@ -71,7 +74,7 @@ static int print_guest(const char *name, int sock) > if (strncmp(comm, PROCESS_NAME, strlen(PROCESS_NAME))) > goto cleanup; > =20 > - printf("%5d %s\n", pid, name); > + printf("%5d %-20s %s\n", pid, name, KVM_INSTANCE_RUNNING); I intended to use "6s" here > =20 > free(comm); > =20 > @@ -109,7 +112,7 @@ static int kvm_list_rootfs(void) > if (dirent->d_type =3D=3D DT_DIR && > strcmp(dirent->d_name, ".") && > strcmp(dirent->d_name, "..")) > - printf(" %s (not running)\n", dirent->d_name); > + printf("%5s %-20s %s\n", "", dirent->d_name, KVM_INSTANCE_SHUTOFF= ); likewise, s/5/6/ > } > =20 > return 0; > @@ -134,7 +137,8 @@ int kvm_cmd_list(int argc, const char **argv, con= st char *prefix) > if (!run && !rootfs) > run =3D rootfs =3D true; > =20 > - printf(" PID GUEST\n"); > + printf("%6s %-20s %s\n", "PID", "NAME", "STATE"); > + printf("------------------------------------\n"); > =20 > if (run) { > r =3D kvm_list_running_instances();