[PATCH v3 9/8] hellolibvirt: Adjust some comments and condition usage

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

 



 v3->v2 difference: Reduced the amount of change to a few comments and
                    adjusting the (NULL == xxx) and (-1 == xxx) checks

Since these are just documentation changes - once ACK'd is it OK to push
now or should I wait for after the freeze?

Tks,

    John
---
 examples/hellolibvirt/hellolibvirt.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/examples/hellolibvirt/hellolibvirt.c b/examples/hellolibvirt/hellolibvirt.c
index 234637e..335a75e 100644
--- a/examples/hellolibvirt/hellolibvirt.c
+++ b/examples/hellolibvirt/hellolibvirt.c
@@ -1,5 +1,6 @@
 /* This file contains trivial example code to connect to the running
- * hypervisor and gather a few bits of information.  */
+ * hypervisor and gather a few bits of information about domains.
+ * Similar API's exist for storage pools, networks, and interfaces. */
 
 #include <config.h>
 
@@ -15,7 +16,7 @@ showError(virConnectPtr conn)
     virErrorPtr err;
 
     err = malloc(sizeof(*err));
-    if (NULL == err) {
+    if (!err) {
         printf("Could not allocate memory for error data\n");
         goto out;
     }
@@ -56,7 +57,7 @@ showHypervisorInfo(virConnectPtr conn)
      * to fail if, for example, there is no connection to a
      * hypervisor, so check what it returns. */
     hvType = virConnectGetType(conn);
-    if (NULL == hvType) {
+    if (!hvType) {
         ret = 1;
         printf("Failed to get hypervisor type\n");
         showError(conn);
@@ -93,7 +94,7 @@ showDomains(virConnectPtr conn)
     char **nameList = NULL;
 
     numActiveDomains = virConnectNumOfDomains(conn);
-    if (-1 == numActiveDomains) {
+    if (numActiveDomains == -1) {
         ret = 1;
         printf("Failed to get number of active domains\n");
         showError(conn);
@@ -101,7 +102,7 @@ showDomains(virConnectPtr conn)
     }
 
     numInactiveDomains = virConnectNumOfDefinedDomains(conn);
-    if (-1 == numInactiveDomains) {
+    if (numInactiveDomains == -1) {
         ret = 1;
         printf("Failed to get number of inactive domains\n");
         showError(conn);
@@ -113,17 +114,20 @@ showDomains(virConnectPtr conn)
 
     nameList = malloc(sizeof(*nameList) * numInactiveDomains);
 
-    if (NULL == nameList) {
+    if (!nameList) {
         ret = 1;
         printf("Could not allocate memory for list of inactive domains\n");
         goto out;
     }
 
+    /* The virConnectListDomains() will return a list of the active domains.
+     * Alternatively the virConnectListAllDomains() API would return a list
+     * of both active and inactive domains */
     numNames = virConnectListDefinedDomains(conn,
                                             nameList,
                                             numInactiveDomains);
 
-    if (-1 == numNames) {
+    if (numNames == -1) {
         ret = 1;
         printf("Could not get list of defined domains from hypervisor\n");
         showError(conn);
@@ -136,9 +140,7 @@ showDomains(virConnectPtr conn)
 
     for (i = 0 ; i < numNames ; i++) {
         printf("  %s\n", *(nameList + i));
-        /* The API documentation doesn't say so, but the names
-         * returned by virConnectListDefinedDomains are strdup'd and
-         * must be freed here.  */
+        /* must free the returned named per the API documentation */
         free(*(nameList + i));
     }
 
@@ -163,7 +165,7 @@ main(int argc, char *argv[])
      * except, possibly, the URI of the hypervisor. */
     conn = virConnectOpenAuth(uri, virConnectAuthPtrDefault, 0);
 
-    if (NULL == conn) {
+    if (!conn) {
         ret = 1;
         printf("No connection to hypervisor\n");
         showError(conn);
@@ -171,7 +173,7 @@ main(int argc, char *argv[])
     }
 
     uri = virConnectGetURI(conn);
-    if (NULL == uri) {
+    if (!uri) {
         ret = 1;
         printf("Failed to get URI for hypervisor connection\n");
         showError(conn);
-- 
1.7.11.7

--
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]