]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
examples/dommigrate: Make retval portable
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 8 Nov 2021 12:33:09 +0000 (13:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Nov 2021 16:17:16 +0000 (17:17 +0100)
Currently, the dommigrate example returns 0 or 1 for success or
failure state, respectively. Except for a few cases where it
forgot to change the @ret variable just before jumping onto the
'cleanup' label. Making the code follow our usual pattern
(initialize @ret to an error value and set it to success value
only at the end) fixes those cases. Also, using EXIT_SUCCESS and
EXIT_FAILURE is more portable (even though on my system they are
just an alias to values the example already uses).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
examples/c/domain/dommigrate.c

index b1641efb9a956e4bb0202fd2f4364c48f05da822..3d32ada6d3197f133647e2e0f94701636b304e17 100644 (file)
@@ -36,7 +36,7 @@ int
 main(int argc, char *argv[])
 {
     char *src_uri, *dst_uri, *domname;
-    int ret = 0;
+    int ret = EXIT_FAILURE;
     virConnectPtr conn = NULL;
     virDomainPtr dom = NULL;
 
@@ -52,7 +52,6 @@ main(int argc, char *argv[])
     printf("Attempting to connect to the source hypervisor...\n");
     conn = virConnectOpenAuth(src_uri, virConnectAuthPtrDefault, 0);
     if (!conn) {
-        ret = 1;
         fprintf(stderr, "No connection to the source hypervisor: %s.\n",
                 virGetLastErrorMessage());
         goto out;
@@ -74,6 +73,7 @@ main(int argc, char *argv[])
     }
 
     printf("Migration finished with success.\n");
+    ret = EXIT_SUCCESS;
 
  cleanup:
     if (dom != NULL)