Re: [PATCHv2] build: add stubs so mdns code can be unconditionally compiled

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 01, 2012 at 05:52:42PM -0600, Eric Blake wrote:
> The recent changes to test exported symbols flushed out the fact
> that we were unconditionally linking against symbols that were
> only conditionally compiled under HAVE_AVAHI.
> 
> * src/Makefile.am (libvirt_net_rpc_server_la_SOURCES): Compile
> virnetservermdns unconditionally.
> * configure.ac (HAVE_AVAHI): Drop unused automake conditional.
> * src/rpc/virnetservermdns.c: Add fallbacks when Avahi is not
> present.
> 
> ---
> 
> Definitely more involved than splitting out a separate .syms file, so
> I'm not sure whether this approach is better than the v1 approach.
> But I did promise to propose this alternative, so here it is.  I tested
> both with and without avahi development libraries present.
> 
>  configure.ac               |  1 -
>  src/Makefile.am            |  8 +---
>  src/rpc/virnetservermdns.c | 98 ++++++++++++++++++++++++++++++++++++++++++----
>  3 files changed, 91 insertions(+), 16 deletions(-)

Hmm, there should be a change to src/rpc/virnetserver.c to
remove the avahi conditionals there I think.  If everything
still operates when avahi is disabled, then I think I prefer
this patch, even though it is more complex, because it means
the HAVE_AVAHI conditionals don't spread across the source
tree to every user of this API.

ACK

> diff --git a/configure.ac b/configure.ac
> index 400ac3b..e93bbb5 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1248,7 +1248,6 @@ if test "x$with_avahi" = "xyes" || test "x$with_avahi" = "xcheck"; then
>        [whether Avahi is used to broadcast server presense])
>    fi
>  fi
> -AM_CONDITIONAL([HAVE_AVAHI], [test "x$with_avahi" = "xyes"])
>  AC_SUBST([AVAHI_CFLAGS])
>  AC_SUBST([AVAHI_LIBS])
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index b48ce65..8fbbabd 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -1529,14 +1529,8 @@ libvirt_net_rpc_server_la_SOURCES = \
>  	rpc/virnetserverprogram.h rpc/virnetserverprogram.c \
>  	rpc/virnetserverservice.h rpc/virnetserverservice.c \
>  	rpc/virnetserverclient.h rpc/virnetserverclient.c \
> +	rpc/virnetservermdns.h rpc/virnetservermdns.c \
>  	rpc/virnetserver.h rpc/virnetserver.c
> -if HAVE_AVAHI
> -libvirt_net_rpc_server_la_SOURCES += \
> -	rpc/virnetservermdns.h rpc/virnetservermdns.c
> -else
> -EXTRA_DIST += \
> -	rpc/virnetservermdns.h rpc/virnetservermdns.c
> -endif
>  libvirt_net_rpc_server_la_CFLAGS = \
>  			$(AVAHI_CFLAGS) \
>  			$(XDR_CFLAGS) \
> diff --git a/src/rpc/virnetservermdns.c b/src/rpc/virnetservermdns.c
> index 274be19..7c43c40 100644
> --- a/src/rpc/virnetservermdns.c
> +++ b/src/rpc/virnetservermdns.c
> @@ -1,7 +1,7 @@
>  /*
>   * virnetservermdns.c: advertise server sockets
>   *
> - * Copyright (C) 2011 Red Hat, Inc.
> + * Copyright (C) 2011-2012 Red Hat, Inc.
>   * Copyright (C) 2007 Daniel P. Berrange
>   *
>   * Derived from Avahi example service provider code.
> @@ -29,14 +29,16 @@
>  #include <stdio.h>
>  #include <stdlib.h>
> 
> -#include <avahi-client/client.h>
> -#include <avahi-client/publish.h>
> +#if HAVE_AVAHI
> +# include <avahi-client/client.h>
> +# include <avahi-client/publish.h>
> 
> -#include <avahi-common/alternative.h>
> -#include <avahi-common/simple-watch.h>
> -#include <avahi-common/malloc.h>
> -#include <avahi-common/error.h>
> -#include <avahi-common/timeval.h>
> +# include <avahi-common/alternative.h>
> +# include <avahi-common/simple-watch.h>
> +# include <avahi-common/malloc.h>
> +# include <avahi-common/error.h>
> +# include <avahi-common/timeval.h>
> +#endif
> 
>  #include "virnetservermdns.h"
>  #include "event.h"
> @@ -55,18 +57,23 @@ struct _virNetServerMDNSEntry {
> 
>  struct _virNetServerMDNSGroup {
>      virNetServerMDNSPtr mdns;
> +#if HAVE_AVAHI
>      AvahiEntryGroup *handle;
> +#endif
>      char *name;
>      virNetServerMDNSEntryPtr entry;
>      virNetServerMDNSGroupPtr next;
>  };
> 
>  struct _virNetServerMDNS {
> +#if HAVE_AVAHI
>      AvahiClient *client;
>      AvahiPoll *poller;
> +#endif
>      virNetServerMDNSGroupPtr group;
>  };
> 
> +#if HAVE_AVAHI
>  /* Avahi API requires this struct name in the app :-( */
>  struct AvahiWatch {
>      int watch;
> @@ -612,3 +619,78 @@ void virNetServerMDNSEntryFree(virNetServerMDNSEntryPtr entry)
>      VIR_FREE(entry->type);
>      VIR_FREE(entry);
>  }
> +
> +#else /* ! HAVE_AVAHI */
> +
> +static const char *unsupported = N_("avahi not available at build time");
> +
> +virNetServerMDNS *
> +virNetServerMDNSNew(void)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +    return NULL;
> +}
> +
> +int
> +virNetServerMDNSStart(virNetServerMDNS *mdns ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +    return -1;
> +}
> +
> +virNetServerMDNSGroupPtr
> +virNetServerMDNSAddGroup(virNetServerMDNS *mdns ATTRIBUTE_UNUSED,
> +                         const char *name ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +    return NULL;
> +}
> +
> +void
> +virNetServerMDNSRemoveGroup(virNetServerMDNSPtr mdns ATTRIBUTE_UNUSED,
> +                            virNetServerMDNSGroupPtr group ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +}
> +
> +virNetServerMDNSEntryPtr
> +virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group ATTRIBUTE_UNUSED,
> +                         const char *type ATTRIBUTE_UNUSED,
> +                         int port ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +    return NULL;
> +}
> +
> +void
> +virNetServerMDNSRemoveEntry(virNetServerMDNSGroupPtr group ATTRIBUTE_UNUSED,
> +                            virNetServerMDNSEntryPtr entry ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +}
> +
> +void
> +virNetServerMDNSStop(virNetServerMDNSPtr mdns ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +}
> +
> +void
> +virNetServerMDNSFree(virNetServerMDNSPtr mdns ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +}
> +
> +void
> +virNetServerMDNSGroupFree(virNetServerMDNSGroupPtr grp ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +}
> +
> +void
> +virNetServerMDNSEntryFree(virNetServerMDNSEntryPtr entry ATTRIBUTE_UNUSED)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +}
> +
> +#endif /* ! HAVE_AVAHI */
> -- 


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]