From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liming Wang Subject: [PATCH 2/2] kvm tools: handle failure of command Date: Wed, 10 Aug 2011 10:44:09 +0800 Message-ID: <1312944249-4946-2-git-send-email-walimisdev@gmail.com> References: <1312944249-4946-1-git-send-email-walimisdev@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , Asias He , To: Pekka Enberg Return-path: Received: from mail.windriver.com ([147.11.1.11]:54352 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751568Ab1HJDCI (ORCPT ); Tue, 9 Aug 2011 23:02:08 -0400 In-Reply-To: <1312944249-4946-1-git-send-email-walimisdev@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: handle failure of calling command function, especially, only handle EPERM error now. Signed-off-by: Liming Wang --- 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