[libvirt] [PATCH v2] virsh: fix build without readline

Roman Bogorodskiy posted 1 patch 6 years, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20180113144600.54404-1-bogorodskiy@gmail.com
tools/Makefile.am            | 20 ++------------------
tools/virsh-completer.c      | 23 +++++++++++++++++++++++
tools/virt-admin-completer.c | 12 ++++++++++++
tools/vsh.c                  |  2 +-
4 files changed, 38 insertions(+), 19 deletions(-)
[libvirt] [PATCH v2] virsh: fix build without readline
Posted by Roman Bogorodskiy 6 years, 3 months ago
Completion in virsh is enabled when readline is available. In order to
fix build when it's not available, do the following:

 * Unconditionally add virsh-completer.[ch] and
   virt-admin-completer.[ch] to the build, and provide stub functions
   for when readline is not available. This way virsh builds without
   complaining about missing symbols used for 'completer' in
   vshCmdOptDef;
 * In cmdComplete(), mark unused arguments when there's no readline
   with ATTRIBUTE_UNUSED.
---
 tools/Makefile.am            | 20 ++------------------
 tools/virsh-completer.c      | 23 +++++++++++++++++++++++
 tools/virt-admin-completer.c | 12 ++++++++++++
 tools/vsh.c                  |  2 +-
 4 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 48125f516..8cb66db7d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -229,17 +229,9 @@ virsh_SOURCES = \
 		virsh-snapshot.c virsh-snapshot.h \
 		virsh-util.c virsh-util.h \
 		virsh-volume.c virsh-volume.h \
+		virsh-completer.c virsh-completer.h \
 		$(NULL)
 
-VIRSH_COMPLETER = \
-		virsh-completer.c virsh-completer.h
-
-if WITH_READLINE
-virsh_SOURCES += $(VIRSH_COMPLETER)
-else ! WITH_READLINE
-EXTRA_DIST += $(VIRSH_COMPLETER)
-endif ! WITH_READLINE
-
 virsh_LDFLAGS = \
 		$(AM_LDFLAGS) \
 		$(PIE_LDFLAGS) \
@@ -256,17 +248,9 @@ virsh_CFLAGS = \
 
 virt_admin_SOURCES = \
 		virt-admin.c virt-admin.h \
+		virt-admin-completer.c virt-admin-completer.h \
 		$(NULL)
 
-VIRT_ADMIN_COMPLETER = \
-		virt-admin-completer.c virt-admin-completer.h
-
-if WITH_READLINE
-virt_admin_SOURCES += $(VIRT_ADMIN_COMPLETER)
-else ! WITH_READLINE
-EXTRA_DIST += $(VIRT_ADMIN_COMPLETER)
-endif ! WITH_READLINE
-
 virt_admin_LDFLAGS = \
 		$(AM_LDFLAGS) \
 		$(COVERAGE_LDFLAGS) \
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 48dd9fbc2..fd92ee8db 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -31,6 +31,7 @@
 #include "virxml.h"
 
 
+#ifdef WITH_READLINE
 char **
 virshDomainNameCompleter(vshControl *ctl,
                          const vshCmd *cmd ATTRIBUTE_UNUSED,
@@ -147,3 +148,25 @@ virshDomainInterfaceCompleter(vshControl *ctl,
     virStringListFree(ret);
     return NULL;
 }
+#else
+char **
+virshDomainNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+                         const vshCmd *cmd ATTRIBUTE_UNUSED,
+                         unsigned int flags)
+{
+    virCheckFlags(-1, NULL);
+
+    return NULL;
+}
+
+
+char **
+virshDomainInterfaceCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+                              const vshCmd *cmd ATTRIBUTE_UNUSED,
+                              unsigned int flags)
+{
+    virCheckFlags(-1, NULL);
+
+    return NULL;
+}
+#endif /* WITH_READLINE */
diff --git a/tools/virt-admin-completer.c b/tools/virt-admin-completer.c
index 2cd471f32..a432f0977 100644
--- a/tools/virt-admin-completer.c
+++ b/tools/virt-admin-completer.c
@@ -30,6 +30,7 @@
 #include "virstring.h"
 
 
+#ifdef WITH_READLINE
 char **
 vshAdmServerCompleter(vshControl *ctl,
                       const vshCmd *cmd ATTRIBUTE_UNUSED,
@@ -74,3 +75,14 @@ vshAdmServerCompleter(vshControl *ctl,
     VIR_FREE(ret);
     return ret;
 }
+#else
+char **
+vshAdmServerCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+                      const vshCmd *cmd ATTRIBUTE_UNUSED,
+                      unsigned int flags)
+{
+    virCheckFlags(-1, NULL);
+
+    return NULL;
+}
+#endif /* WITH_READLINE */
diff --git a/tools/vsh.c b/tools/vsh.c
index 4426c08d6..59c8a440e 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -3500,7 +3500,7 @@ const vshCmdInfo info_complete[] = {
 };
 
 bool
-cmdComplete(vshControl *ctl, const vshCmd *cmd)
+cmdComplete(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     bool ret = false;
 #ifdef WITH_READLINE
-- 
2.15.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] virsh: fix build without readline
Posted by Erik Skultety 6 years, 3 months ago
On Sat, Jan 13, 2018 at 06:46:00PM +0400, Roman Bogorodskiy wrote:
> Completion in virsh is enabled when readline is available. In order to
> fix build when it's not available, do the following:
>
>  * Unconditionally add virsh-completer.[ch] and
>    virt-admin-completer.[ch] to the build, and provide stub functions
>    for when readline is not available. This way virsh builds without
>    complaining about missing symbols used for 'completer' in
>    vshCmdOptDef;
>  * In cmdComplete(), mark unused arguments when there's no readline
>    with ATTRIBUTE_UNUSED.
> ---

...

>
>
> +#ifdef WITH_READLINE
>  char **
>  virshDomainNameCompleter(vshControl *ctl,
>                           const vshCmd *cmd ATTRIBUTE_UNUSED,
> @@ -147,3 +148,25 @@ virshDomainInterfaceCompleter(vshControl *ctl,
>      virStringListFree(ret);
>      return NULL;
>  }
> +#else
> +char **
> +virshDomainNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
> +                         const vshCmd *cmd ATTRIBUTE_UNUSED,
> +                         unsigned int flags)
> +{
> +    virCheckFlags(-1, NULL);
> +
> +    return NULL;
> +}

Do you actually need to define these "no readline" function versions? I'm
asking because the completer callbacks are transitively invoked from
vshReadlineCompletion (and friends) which is only called from the cmdComplete
which both your and Michal's patch handles. So, are you experiencing any
problems on any platforms without these hunks? (I compiles fine with just the
first and last hunk applied, obviously no readline support)

Anyhow, I went ahead and reviewed Michal's patches, so unless you really need
the hunks I mentioned in the previous paragraph, let's go with Michal's instead.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] virsh: fix build without readline
Posted by Roman Bogorodskiy 6 years, 3 months ago
  Erik Skultety wrote:

> On Sat, Jan 13, 2018 at 06:46:00PM +0400, Roman Bogorodskiy wrote:
> > Completion in virsh is enabled when readline is available. In order to
> > fix build when it's not available, do the following:
> >
> >  * Unconditionally add virsh-completer.[ch] and
> >    virt-admin-completer.[ch] to the build, and provide stub functions
> >    for when readline is not available. This way virsh builds without
> >    complaining about missing symbols used for 'completer' in
> >    vshCmdOptDef;
> >  * In cmdComplete(), mark unused arguments when there's no readline
> >    with ATTRIBUTE_UNUSED.
> > ---
> 
> ...
> 
> >
> >
> > +#ifdef WITH_READLINE
> >  char **
> >  virshDomainNameCompleter(vshControl *ctl,
> >                           const vshCmd *cmd ATTRIBUTE_UNUSED,
> > @@ -147,3 +148,25 @@ virshDomainInterfaceCompleter(vshControl *ctl,
> >      virStringListFree(ret);
> >      return NULL;
> >  }
> > +#else
> > +char **
> > +virshDomainNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
> > +                         const vshCmd *cmd ATTRIBUTE_UNUSED,
> > +                         unsigned int flags)
> > +{
> > +    virCheckFlags(-1, NULL);
> > +
> > +    return NULL;
> > +}
> 
> Do you actually need to define these "no readline" function versions? I'm
> asking because the completer callbacks are transitively invoked from
> vshReadlineCompletion (and friends) which is only called from the cmdComplete
> which both your and Michal's patch handles. So, are you experiencing any
> problems on any platforms without these hunks? (I compiles fine with just the
> first and last hunk applied, obviously no readline support)
> 
> Anyhow, I went ahead and reviewed Michal's patches, so unless you really need
> the hunks I mentioned in the previous paragraph, let's go with Michal's instead.
> 
> Erik

These stub versions are not needed indeed, let's go with Michal's patches.

Roman Bogorodskiy
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list