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)
{
virCommand *cmd;
char *outbuf;
g_autoptr(virCommand) cmd = NULL;
g_autofree char *outbuf = NULL;
char *temp;
int veid;
bool ok;
cmd = virCommandNewArgList(VZLIST, name, "-ovpsid", "-H", NULL);
virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0) {
virCommandFree(cmd);
VIR_FREE(outbuf);
if (virCommandRun(cmd, NULL) < 0)
return -1;
}
virCommandFree(cmd);
ok = virStrToLong_i(outbuf, &temp, 10, &veid) == 0 && *temp == '\n';
VIR_FREE(outbuf);
if (ok && veid >= 0)
return veid;