openvz: refactor openvzGetVEID

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2021-12-13 18:47:47 +01:00
parent 680d8c91e8
commit 0dfb73a511

View File

@ -978,23 +978,18 @@ static int openvzAssignUUIDs(void)
int openvzGetVEID(const char *name) int openvzGetVEID(const char *name)
{ {
virCommand *cmd; g_autoptr(virCommand) cmd = NULL;
char *outbuf; g_autofree char *outbuf = NULL;
char *temp; char *temp;
int veid; int veid;
bool ok; bool ok;
cmd = virCommandNewArgList(VZLIST, name, "-ovpsid", "-H", NULL); cmd = virCommandNewArgList(VZLIST, name, "-ovpsid", "-H", NULL);
virCommandSetOutputBuffer(cmd, &outbuf); virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0) { if (virCommandRun(cmd, NULL) < 0)
virCommandFree(cmd);
VIR_FREE(outbuf);
return -1; return -1;
}
virCommandFree(cmd);
ok = virStrToLong_i(outbuf, &temp, 10, &veid) == 0 && *temp == '\n'; ok = virStrToLong_i(outbuf, &temp, 10, &veid) == 0 && *temp == '\n';
VIR_FREE(outbuf);
if (ok && veid >= 0) if (ok && veid >= 0)
return veid; return veid;