]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Fix virshDomainInterfaceSourceCompleter
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 5 Dec 2019 15:00:22 +0000 (16:00 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 7 Jan 2020 15:12:55 +0000 (16:12 +0100)
Introduced in v5.10.0-449-gcf44ec5577 it used
virshCommaStringListComplete() to generate list of options. But
this is not correct because the '--source' argument of the
'domifaddr' doesn't accept a string list (for instance
"arp,agent,lease") rather than a single string. Therefore, the
completer must return these strings separately and thus must
refrain from using virshCommaStringListComplete().

At the same time, now that we have strings we need declared as
an enum we can use TypeToString() instead of copying strings.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tools/virsh-completer-domain.c
tools/virsh-domain-monitor.c
tools/virsh-domain-monitor.h
tools/virsh.h

index 9423d2efb3589b470235c3974a8d30fbde3c9ee6..6da603048e3f06fd568fe17f4008c52f7e9dd6b4 100644 (file)
@@ -24,6 +24,7 @@
 #include "viralloc.h"
 #include "virmacaddr.h"
 #include "virsh-domain.h"
+#include "virsh-domain-monitor.h"
 #include "virsh-util.h"
 #include "virsh.h"
 #include "virstring.h"
@@ -299,17 +300,19 @@ virshDomainShutdownModeCompleter(vshControl *ctl,
 
 
 char **
-virshDomainInterfaceAddrSourceCompleter(vshControl *ctl,
-                                        const vshCmd *cmd,
+virshDomainInterfaceAddrSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
+                                        const vshCmd *cmd G_GNUC_UNUSED,
                                         unsigned int flags)
 {
-    const char *sources[] = {"lease", "agent", "arp", NULL};
-    const char *source = NULL;
+    char **ret = NULL;
+    size_t i;
 
     virCheckFlags(0, NULL);
 
-    if (vshCommandOptStringQuiet(ctl, cmd, "source", &source) < 0)
-        return NULL;
+    ret = g_new0(typeof(*ret), VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LAST + 1);
 
-    return virshCommaStringListComplete(source, sources);
+    for (i = 0; i < VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LAST; i++)
+        ret[i] = g_strdup(virshDomainInterfaceAddressesSourceTypeToString(i));
+
+    return ret;
 }
index de4abbaee7c076f463122fdf69b763fbb9400cb0..97301f71f9e0b9c13255ce3b7d3869a233510990 100644 (file)
@@ -2358,7 +2358,6 @@ static const vshCmdOptDef opts_domifaddr[] = {
     {.name = NULL}
 };
 
-VIR_ENUM_DECL(virshDomainInterfaceAddressesSource);
 VIR_ENUM_IMPL(virshDomainInterfaceAddressesSource,
               VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LAST,
               "lease",
index 11a9156ae21fd4c748a129055e986efa03a72eab..0de47c50c4341a60588d85c334160edff800eb3e 100644 (file)
@@ -26,4 +26,6 @@ char *virshGetDomainDescription(vshControl *ctl, virDomainPtr dom,
                                 bool title, unsigned int flags)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
 
+VIR_ENUM_DECL(virshDomainInterfaceAddressesSource);
+
 extern const vshCmdDef domMonitoringCmds[];
index d84659124aca0b302398fae574c99b0c0033a45f..903a2e53b6aacab640519390f028a590f697f2ae 100644 (file)
@@ -31,6 +31,7 @@
 #include "virpolkit.h"
 #include "vsh.h"
 #include "virsh-completer.h"
+#include "virenum.h"
 
 #define VIRSH_PROMPT_RW    "virsh # "
 #define VIRSH_PROMPT_RO    "virsh > "