mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 03:21:19 +00:00
openvz: refactor openvzVEGetStringParam
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
7cd718cca5
commit
4a56179646
@ -58,27 +58,22 @@ char*
|
|||||||
openvzVEGetStringParam(virDomainPtr domain, const char* param)
|
openvzVEGetStringParam(virDomainPtr domain, const char* param)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *output = NULL;
|
g_autofree char *output = NULL;
|
||||||
|
|
||||||
virCommand *cmd = virCommandNewArgList(VZLIST,
|
g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST,
|
||||||
"-o",
|
"-o",
|
||||||
param,
|
param,
|
||||||
domain->name,
|
domain->name,
|
||||||
"-H", NULL);
|
"-H", NULL);
|
||||||
|
|
||||||
virCommandSetOutputBuffer(cmd, &output);
|
virCommandSetOutputBuffer(cmd, &output);
|
||||||
if (virCommandRun(cmd, NULL) < 0) {
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
VIR_FREE(output);
|
return NULL;
|
||||||
/* virCommandRun sets the virError */
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* delete trailing newline */
|
/* delete trailing newline */
|
||||||
len = strlen(output);
|
len = strlen(output);
|
||||||
if (len && output[len - 1] == '\n')
|
if (len && output[len - 1] == '\n')
|
||||||
output[len - 1] = '\0';
|
output[len - 1] = '\0';
|
||||||
|
|
||||||
cleanup:
|
return g_steal_pointer(&output);
|
||||||
virCommandFree(cmd);
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user