Re: [PATCH 2/2] dom event example: Add error check to impl call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09.05.2013 23:17, Jesse J. Cook wrote:
> From: "Jesse J. Cook" <jesse.j.cook@xxxxxxxxxxxxxx>
> 
> Added error checking to virEventRegisterDefaultImpl call for consistency.
> ---
>  examples/domain-events/events-c/event-test.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
> index 09ec6aa..046c36e 100644
> --- a/examples/domain-events/events-c/event-test.c
> +++ b/examples/domain-events/events-c/event-test.c
> @@ -474,7 +474,11 @@ int main(int argc, char **argv)
>                  err && err->message ? err->message: "Unknown error");
>      }
>  
> -    virEventRegisterDefaultImpl();
> +    if(0 != virEventRegisterDefaultImpl()) {

We tend to write it vice versa. Moreover, there should be a space between 'if' and '(':
  if (virEventRegisterDefaultImpl() < 0) {

> +        virErrorPtr err = virGetLastError();

But here is it perfectly safe to call virGetLastError() because the only way we could get here
is where virInitialize reported success.

> +        fprintf(stderr, "Failed to register event implementation: %s\n",
> +                err && err->message ? err->message: "Unknown error");

Again, we should return -1 here.

> +    }
>  
>      virConnectPtr dconn = NULL;
>      dconn = virConnectOpenAuth(argc > 1 ? argv[1] : NULL,
> 

ACK with this squashed in:

diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index bee3f78..301caad 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -473,10 +473,11 @@ int main(int argc, char **argv)
         return -1;
     }
 
-    if(0 != virEventRegisterDefaultImpl()) {
+    if (virEventRegisterDefaultImpl() < 0) {
         virErrorPtr err = virGetLastError();
         fprintf(stderr, "Failed to register event implementation: %s\n",
                 err && err->message ? err->message: "Unknown error");
+        return -1;
     }
 
     virConnectPtr dconn = NULL;


Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]