From: walimis Subject: Re: [PATCH 2/2] kvm tools: handle failure of command Date: Wed, 10 Aug 2011 13:03:40 +0800 Message-ID: <20110810050340.GB16258@walimis-desktop> References: <1312944249-4946-1-git-send-email-walimisdev@gmail.com> <1312944249-4946-2-git-send-email-walimisdev@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , Asias He , kvm@vger.kernel.org To: Pekka Enberg Return-path: Received: from mail-qy0-f181.google.com ([209.85.216.181]:34438 "EHLO mail-qy0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750836Ab1HJFTx (ORCPT ); Wed, 10 Aug 2011 01:19:53 -0400 Received: by qyk34 with SMTP id 34so417388qyk.19 for ; Tue, 09 Aug 2011 22:19:53 -0700 (PDT) Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Aug 10, 2011 at 08:02:01AM +0300, Pekka Enberg wrote: >On Wed, Aug 10, 2011 at 5:44 AM, Liming Wang wr= ote: >> handle failure of calling command function, especially, only handle >> EPERM error now. >> >> Signed-off-by: Liming Wang > >I applied the patch because I absolutely loved the error handling >cleanups from the previous patch. However, out of curiosity, are you >seeing EPERM with some command in particular? Yes. Because I'm using ubuntu and if I don't use sudo to execute "kvm pause", pause command can't work and doesn't prompt anything. BTW, do you always login as "root" user? walimis > >> --- >> =E7=88=90ools/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" >> >> =E7=88=8Ftruct cmd_struct kvm_commands[] =3D { >> ? ? ? =E7=88=97 "pause", ? ? =E7=88=87vm_cmd_pause, ? ? ? ? =E7=87=A6= ULL, ? ? ? ? 0 }, >> @@ -59,6 +60,7 @@ int handle_command(struct cmd_struct *command, int= argc, const char **argv) >> =E7=88=97 >> ? ? ? =E7=88=8Ftruct cmd_struct *p; >> ? ? ? =E7=87=BEonst char *prefix =3D NULL; >> + ? ? ? int ret =3D 0; >> >> ? ? ? =E7=88=84f (!argv || !*argv) { >> ? ? ? ? ? ? ? =E7=88=8C =3D kvm_get_command(command, "help"); >> @@ -74,5 +76,12 @@ int handle_command(struct cmd_struct *command, in= t argc, const char **argv) >> ? ? ? ? ? ? ? =E7=88=8Eeturn EINVAL; >> ? ? ? =E7=88=99 >> >> - ? ? ? return p->fn(argc - 1, &argv[1], prefix); >> + ? ? ? ret =3D p->fn(argc - 1, &argv[1], prefix); >> + ? ? ? if (ret < 0) >> + ? ? ? { >> + ? ? ? ? ? ? ? if (errno =3D=3D EPERM) >> + ? ? ? ? ? ? ? ? ? ? ? die("Permission error - are you root?"); >> + ? ? ? } >> + >> + ? ? ? return ret; >> =E7=88=99 >> -- >> 1.7.0.4 >> >> -- >> To unsubscribe from this list: send the line "unsubscribe kvm" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at =E7=88=83ttp://vger.kernel.org/majordomo-info= =2Ehtml >>