]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
openvz: refactor openvzConnectListDomains
authorJán Tomko <jtomko@redhat.com>
Mon, 13 Dec 2021 18:13:24 +0000 (19:13 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 14 Dec 2021 15:41:05 +0000 (16:41 +0100)
Use g_auto where possible, reduce scope of some variables and remove
pointless ret and rc variables.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/openvz/openvz_driver.c

index cffdb208980aea8c8ef82c5892839312e7bec323..fa5ded54ec36ad1e18fc5dae5c11489ee94a4255 100644 (file)
@@ -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)