[libvirt PATCH 08/20] openvz: refactor openvzConnectListDomains

Ján Tomko jtomko at redhat.com
Mon Dec 13 18:43:00 UTC 2021


Use g_auto where possible, reduce scope of some variables and remove
pointless ret and rc variables.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/openvz/openvz_driver.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index cffdb20898..fa5ded54ec 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1334,44 +1334,37 @@ static int openvzConnectListDomains(virConnectPtr conn G_GNUC_UNUSED,
                                     int *ids, int nids)
 {
     int got = 0;
-    int veid;
-    int outfd = -1;
-    int rc = -1;
-    int ret;
-    char buf[32];
-    char *endptr;
-    virCommand *cmd = virCommandNewArgList(VZLIST, "-ovpsid", "-H", NULL);
+    VIR_AUTOCLOSE outfd = -1;
+    g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST, "-ovpsid", "-H", NULL);
 
     virCommandSetOutputFD(cmd, &outfd);
     if (virCommandRunAsync(cmd, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     while (got < nids) {
-        ret = openvz_readline(outfd, buf, 32);
-        if (!ret)
+        char *endptr;
+        char buf[32];
+        int veid;
+
+        if (openvz_readline(outfd, buf, 32) == 0)
             break;
         if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Could not parse VPS ID %s"), buf);
             continue;
         }
-        ids[got] = veid;
-        got ++;
+        ids[got++] = veid;
     }
 
     if (virCommandWait(cmd, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     if (VIR_CLOSE(outfd) < 0) {
         virReportSystemError(errno, "%s", _("failed to close file"));
-        goto cleanup;
+        return -1;
     }
 
-    rc = got;
- cleanup:
-    VIR_FORCE_CLOSE(outfd);
-    virCommandFree(cmd);
-    return rc;
+    return got;
 }
 
 static int openvzConnectNumOfDomains(virConnectPtr conn)
-- 
2.31.1




More information about the libvir-list mailing list