openvz: refactor openvzVEGetStringParam

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 19:28:27 +01:00
parent 7cd718cca5
commit 4a56179646

View File

@ -58,27 +58,22 @@ char*
openvzVEGetStringParam(virDomainPtr domain, const char* param)
{
int len;
char *output = NULL;
g_autofree char *output = NULL;
virCommand *cmd = virCommandNewArgList(VZLIST,
"-o",
param,
domain->name,
"-H", NULL);
g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST,
"-o",
param,
domain->name,
"-H", NULL);
virCommandSetOutputBuffer(cmd, &output);
if (virCommandRun(cmd, NULL) < 0) {
VIR_FREE(output);
/* virCommandRun sets the virError */
goto cleanup;
}
if (virCommandRun(cmd, NULL) < 0)
return NULL;
/* delete trailing newline */
len = strlen(output);
if (len && output[len - 1] == '\n')
output[len - 1] = '\0';
cleanup:
virCommandFree(cmd);
return output;
return g_steal_pointer(&output);
}