mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
util: dnsmasq: refactor CapsRefresh
Use two variables with automatic cleanup instead of reusing one. Remove the pointless cleanup label. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
7624796ac8
commit
1b5510c42d
@ -666,9 +666,9 @@ dnsmasqCapsSetFromBuffer(dnsmasqCaps *caps, const char *buf)
|
|||||||
static int
|
static int
|
||||||
dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
|
dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
virCommand *cmd = NULL;
|
g_autoptr(virCommand) vercmd = NULL;
|
||||||
|
g_autoptr(virCommand) helpcmd = NULL;
|
||||||
g_autofree char *help = NULL;
|
g_autofree char *help = NULL;
|
||||||
g_autofree char *version = NULL;
|
g_autofree char *version = NULL;
|
||||||
g_autofree char *complete = NULL;
|
g_autofree char *complete = NULL;
|
||||||
@ -692,31 +692,26 @@ dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
|
|||||||
if (!virFileIsExecutable(caps->binaryPath)) {
|
if (!virFileIsExecutable(caps->binaryPath)) {
|
||||||
virReportSystemError(errno, _("dnsmasq binary %s is not executable"),
|
virReportSystemError(errno, _("dnsmasq binary %s is not executable"),
|
||||||
caps->binaryPath);
|
caps->binaryPath);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNewArgList(caps->binaryPath, "--version", NULL);
|
vercmd = virCommandNewArgList(caps->binaryPath, "--version", NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &version);
|
virCommandSetOutputBuffer(vercmd, &version);
|
||||||
virCommandAddEnvPassCommon(cmd);
|
virCommandAddEnvPassCommon(vercmd);
|
||||||
virCommandClearCaps(cmd);
|
virCommandClearCaps(vercmd);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(vercmd, NULL) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
virCommandFree(cmd);
|
|
||||||
|
|
||||||
cmd = virCommandNewArgList(caps->binaryPath, "--help", NULL);
|
helpcmd = virCommandNewArgList(caps->binaryPath, "--help", NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &help);
|
virCommandSetOutputBuffer(helpcmd, &help);
|
||||||
virCommandAddEnvPassCommon(cmd);
|
virCommandAddEnvPassCommon(helpcmd);
|
||||||
virCommandClearCaps(cmd);
|
virCommandClearCaps(helpcmd);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(helpcmd, NULL) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
complete = g_strdup_printf("%s\n%s", version, help);
|
complete = g_strdup_printf("%s\n%s", version, help);
|
||||||
|
|
||||||
ret = dnsmasqCapsSetFromBuffer(caps, complete);
|
return dnsmasqCapsSetFromBuffer(caps, complete);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCommandFree(cmd);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static dnsmasqCaps *
|
static dnsmasqCaps *
|
||||||
|
Loading…
Reference in New Issue
Block a user