mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 13:35:17 +00:00
openvz: refactor openvzConnectListDefinedDomains
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
80134168fe
commit
5c7c1db2f5
@ -1382,22 +1382,23 @@ static int openvzConnectNumOfDomains(virConnectPtr conn)
|
|||||||
static int openvzConnectListDefinedDomains(virConnectPtr conn G_GNUC_UNUSED,
|
static int openvzConnectListDefinedDomains(virConnectPtr conn G_GNUC_UNUSED,
|
||||||
char **const names, int nnames) {
|
char **const names, int nnames) {
|
||||||
int got = 0;
|
int got = 0;
|
||||||
int veid, outfd = -1, ret;
|
VIR_AUTOCLOSE outfd = -1;
|
||||||
int rc = -1;
|
int ret = -1;
|
||||||
char vpsname[32];
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST,
|
||||||
char buf[32];
|
|
||||||
char *endptr;
|
|
||||||
virCommand *cmd = virCommandNewArgList(VZLIST,
|
|
||||||
"-ovpsid", "-H", "-S", NULL);
|
"-ovpsid", "-H", "-S", NULL);
|
||||||
|
|
||||||
/* the -S options lists only stopped domains */
|
/* the -S options lists only stopped domains */
|
||||||
virCommandSetOutputFD(cmd, &outfd);
|
virCommandSetOutputFD(cmd, &outfd);
|
||||||
if (virCommandRunAsync(cmd, NULL) < 0)
|
if (virCommandRunAsync(cmd, NULL) < 0)
|
||||||
goto out;
|
goto cleanup;
|
||||||
|
|
||||||
while (got < nnames) {
|
while (got < nnames) {
|
||||||
ret = openvz_readline(outfd, buf, 32);
|
char vpsname[32];
|
||||||
if (!ret)
|
char buf[32];
|
||||||
|
char *endptr;
|
||||||
|
int veid;
|
||||||
|
|
||||||
|
if (openvz_readline(outfd, buf, 32) == 0)
|
||||||
break;
|
break;
|
||||||
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -1405,27 +1406,24 @@ static int openvzConnectListDefinedDomains(virConnectPtr conn G_GNUC_UNUSED,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
g_snprintf(vpsname, sizeof(vpsname), "%d", veid);
|
g_snprintf(vpsname, sizeof(vpsname), "%d", veid);
|
||||||
names[got] = g_strdup(vpsname);
|
names[got++] = g_strdup(vpsname);
|
||||||
got ++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCommandWait(cmd, NULL) < 0)
|
if (virCommandWait(cmd, NULL) < 0)
|
||||||
goto out;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_CLOSE(outfd) < 0) {
|
if (VIR_CLOSE(outfd) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("failed to close file"));
|
virReportSystemError(errno, "%s", _("failed to close file"));
|
||||||
goto out;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = got;
|
ret = got;
|
||||||
out:
|
cleanup:
|
||||||
VIR_FORCE_CLOSE(outfd);
|
if (ret < 0) {
|
||||||
virCommandFree(cmd);
|
|
||||||
if (rc < 0) {
|
|
||||||
for (; got >= 0; got--)
|
for (; got >= 0; got--)
|
||||||
VIR_FREE(names[got]);
|
VIR_FREE(names[got]);
|
||||||
}
|
}
|
||||||
return rc;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid)
|
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user