kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Osier Yang <jyang@redhat.com>
To: kvm@vger.kernel.org
Subject: Re: [PATCH] kvm tools: Beautify kvm list output
Date: Wed, 26 Oct 2011 14:13:37 +0800	[thread overview]
Message-ID: <4EA7A511.40600@redhat.com> (raw)
In-Reply-To: <1319611381-27164-1-git-send-email-jyang@redhat.com>

于 2011年10月26日 14:43, Osier Yang 写道:
> 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 <jyang@redhat.com>
> ---
>  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[] = {
>  	OPT_END()
>  };
>  
> +#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;
>  
> -	printf("%5d %s\n", pid, name);
> +	printf("%5d %-20s %s\n", pid, name, KVM_INSTANCE_RUNNING);

I intended to use "6s" here

>  
>  	free(comm);
>  
> @@ -109,7 +112,7 @@ static int kvm_list_rootfs(void)
>  		if (dirent->d_type == 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/

>  	}
>  
>  	return 0;
> @@ -134,7 +137,8 @@ int kvm_cmd_list(int argc, const char **argv, const char *prefix)
>  	if (!run && !rootfs)
>  		run = rootfs = true;
>  
> -	printf("  PID GUEST\n");
> +	printf("%6s %-20s %s\n", "PID", "NAME", "STATE");
> +	printf("------------------------------------\n");
>  
>  	if (run) {
>  		r = kvm_list_running_instances();


           reply	other threads:[~2011-10-26  6:13 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1319611381-27164-1-git-send-email-jyang@redhat.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EA7A511.40600@redhat.com \
    --to=jyang@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).