]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: dnsmasq: refactor CapsRefresh
authorJán Tomko <jtomko@redhat.com>
Fri, 10 Dec 2021 16:21:27 +0000 (17:21 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 14 Dec 2021 15:41:36 +0000 (16:41 +0100)
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>
src/util/virdnsmasq.c

index 2dd9a20377efe8059e20333c7d8002f6827a9ee6..b62e353ceb5119031072cd743604af7ed6107164 100644 (file)
@@ -666,9 +666,9 @@ dnsmasqCapsSetFromBuffer(dnsmasqCaps *caps, const char *buf)
 static int
 dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
 {
-    int ret = -1;
     struct stat sb;
-    virCommand *cmd = NULL;
+    g_autoptr(virCommand) vercmd = NULL;
+    g_autoptr(virCommand) helpcmd = NULL;
     g_autofree char *help = NULL;
     g_autofree char *version = NULL;
     g_autofree char *complete = NULL;
@@ -692,31 +692,26 @@ dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
     if (!virFileIsExecutable(caps->binaryPath)) {
         virReportSystemError(errno, _("dnsmasq binary %s is not executable"),
                              caps->binaryPath);
-        goto cleanup;
+        return -1;
     }
 
-    cmd = virCommandNewArgList(caps->binaryPath, "--version", NULL);
-    virCommandSetOutputBuffer(cmd, &version);
-    virCommandAddEnvPassCommon(cmd);
-    virCommandClearCaps(cmd);
-    if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
-    virCommandFree(cmd);
-
-    cmd = virCommandNewArgList(caps->binaryPath, "--help", NULL);
-    virCommandSetOutputBuffer(cmd, &help);
-    virCommandAddEnvPassCommon(cmd);
-    virCommandClearCaps(cmd);
-    if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
+    vercmd = virCommandNewArgList(caps->binaryPath, "--version", NULL);
+    virCommandSetOutputBuffer(vercmd, &version);
+    virCommandAddEnvPassCommon(vercmd);
+    virCommandClearCaps(vercmd);
+    if (virCommandRun(vercmd, NULL) < 0)
+        return -1;
 
-    complete = g_strdup_printf("%s\n%s", version, help);
+    helpcmd = virCommandNewArgList(caps->binaryPath, "--help", NULL);
+    virCommandSetOutputBuffer(helpcmd, &help);
+    virCommandAddEnvPassCommon(helpcmd);
+    virCommandClearCaps(helpcmd);
+    if (virCommandRun(helpcmd, NULL) < 0)
+        return -1;
 
-    ret = dnsmasqCapsSetFromBuffer(caps, complete);
+    complete = g_strdup_printf("%s\n%s", version, help);
 
- cleanup:
-    virCommandFree(cmd);
-    return ret;
+    return dnsmasqCapsSetFromBuffer(caps, complete);
 }
 
 static dnsmasqCaps *