All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liming Wang <walimisdev@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	Sasha Levin <levinsasha928@gmail.com>,
	Prasad Joshi <prasadjoshi124@gmail.com>,
	Asias He <asias.hejun@gmail.com>, <kvm@vger.kernel.org>
Subject: [PATCH 2/2] kvm tools: handle failure of command
Date: Wed, 10 Aug 2011 10:44:09 +0800	[thread overview]
Message-ID: <1312944249-4946-2-git-send-email-walimisdev@gmail.com> (raw)
In-Reply-To: <1312944249-4946-1-git-send-email-walimisdev@gmail.com>

handle failure of calling command function, especially, only handle
EPERM error now.

Signed-off-by: Liming Wang <walimisdev@gmail.com>
---
 tools/kvm/kvm-cmd.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
index 63a2dbf..6cd4270 100644
--- a/tools/kvm/kvm-cmd.c
+++ b/tools/kvm/kvm-cmd.c
@@ -15,6 +15,7 @@
 #include "kvm/builtin-help.h"
 #include "kvm/kvm-cmd.h"
 #include "kvm/builtin-run.h"
+#include "kvm/util.h"
 
 struct cmd_struct kvm_commands[] = {
 	{ "pause",	kvm_cmd_pause,		NULL,         0 },
@@ -59,6 +60,7 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
 {
 	struct cmd_struct *p;
 	const char *prefix = NULL;
+	int ret = 0;
 
 	if (!argv || !*argv) {
 		p = kvm_get_command(command, "help");
@@ -74,5 +76,12 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
 		return EINVAL;
 	}
 
-	return p->fn(argc - 1, &argv[1], prefix);
+	ret = p->fn(argc - 1, &argv[1], prefix);
+	if (ret < 0)
+	{
+		if (errno == EPERM)
+			die("Permission error - are you root?");
+	}
+
+	return ret;
 }
-- 
1.7.0.4


  reply	other threads:[~2011-08-10  3:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-10  2:44 [PATCH 1/2] kvm tools: convert callback to int and deal with the return value Liming Wang
2011-08-10  2:44 ` Liming Wang [this message]
2011-08-10  5:02   ` [PATCH 2/2] kvm tools: handle failure of command Pekka Enberg
2011-08-10  5:03     ` walimis
2011-08-10  5:30       ` Pekka Enberg
2011-08-10  5:33         ` walimis
2011-08-10  5:53           ` Pekka Enberg
2011-08-10  6:12             ` walimis
2011-08-10  6:35               ` Pekka Enberg
2011-08-10  6:32                 ` walimis
2011-08-10  6:49                   ` Pekka Enberg
2011-08-10  9:28                     ` Asias He

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=1312944249-4946-2-git-send-email-walimisdev@gmail.com \
    --to=walimisdev@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.