[libvirt] Corrected patch

Some netcat implementations does not support unix domain sockets (-U). Distros that ship these implementations often also ships socat, that do support this. This is a reworked patch based on the openSUSE libvirt package. The original patch may be found in this source rpm: http://download.opensuse.org/source/distribution/11.1/repo/oss/suse/src/libv... * configure.in: Check for --with-socat and set USE_SOCAT in config.h * src/remote_internal.c: Honour USE_SOCAT by selecting between netcat/nc and socat at compile time. --- configure.in | 7 +++++++ src/remote_internal.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/configure.in b/configure.in index b905b23..732ef68 100644 --- a/configure.in +++ b/configure.in @@ -153,6 +153,13 @@ if test -n "$MODPROBE"; then [Location or name of the modprobe program]) fi +dnl Check if socat should be used instead of netcat +AC_ARG_WITH([socat], +[ --with-socat use socat instead of netcat (off)]) +if test "$with_socat" = "yes" ; then + AC_DEFINE_UNQUOTED([USE_SOCAT], 1, [whether socat should be used instead of netcat]) +fi + dnl Specific dir for HTML output ? AC_ARG_WITH([html-dir], [AC_HELP_STRING([--with-html-dir=path], [path to base html directory, default $datadir/doc/html])], diff --git a/src/remote_internal.c b/src/remote_internal.c index a58b768..ae44335 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -726,12 +726,28 @@ doRemoteOpen (virConnectPtr conn, cmd_argv[j++] = strdup ("none"); } cmd_argv[j++] = strdup (priv->hostname); +#ifdef USE_SOCAT + cmd_argv[j++] = strdup ("socat"); + cmd_argv[j++] = strdup ("-"); + + char *socat_addr = 0; + if ((asprintf (&socat_addr, "GOPEN:%s", + sockname ? sockname : + (flags & VIR_CONNECT_RO + ? LIBVIRTD_PRIV_UNIX_SOCKET_RO + : LIBVIRTD_PRIV_UNIX_SOCKET))) < 0) { + error (conn, VIR_ERR_SYSTEM_ERROR, strerror (ENOMEM)); + goto failed; + } + cmd_argv[j++] = socat_addr; +#else cmd_argv[j++] = strdup (netcat ? netcat : "nc"); cmd_argv[j++] = strdup ("-U"); cmd_argv[j++] = strdup (sockname ? sockname : (flags & VIR_CONNECT_RO ? LIBVIRTD_PRIV_UNIX_SOCKET_RO : LIBVIRTD_PRIV_UNIX_SOCKET)); +#endif cmd_argv[j++] = 0; assert (j == nr_args); for (j = 0; j < (nr_args-1); j++) -- 1.6.2

On Wed, Aug 05, 2009 at 12:58:33PM +0200, Jonas Eriksson wrote:
Some netcat implementations does not support unix domain sockets (-U). Distros that ship these implementations often also ships socat, that do support this.
This is a reworked patch based on the openSUSE libvirt package. The original patch may be found in this source rpm: http://download.opensuse.org/source/distribution/11.1/repo/oss/suse/src/libv...
* configure.in: Check for --with-socat and set USE_SOCAT in config.h
* src/remote_internal.c: Honour USE_SOCAT by selecting between netcat/nc and socat at compile time.
Changing the binary used at compile time is really not a good idea, because libvirt uses netcat on the remote machine, which is not required to be the same distro as the client machine on whihc you built libvirt. So by making socat vs netcat a compile time option you pretty much guarentee incompatibility between libvirt client & server betweeen distros. It is really better to fix netcat on the distros where -U isn't available. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Thu, Aug 06, 2009 at 12:39:34PM +0100, Daniel P. Berrange wrote:
On Wed, Aug 05, 2009 at 12:58:33PM +0200, Jonas Eriksson wrote:
* src/remote_internal.c: Honour USE_SOCAT by selecting between netcat/nc and socat at compile time.
Changing the binary used at compile time is really not a good idea, because libvirt uses netcat on the remote machine, which is not required to be the same distro as the client machine on whihc you built libvirt. So by making socat vs netcat a compile time option you pretty much guarentee incompatibility between libvirt client & server betweeen distros. It is really better to fix netcat on the distros where -U isn't available.
As for other case where we had multiple binary options, isn't picking up at runtime a possibility, suppose we can catch that 'netcat -U' fails, we could try to fallback to socat. In any case a compile time switch doesn't sounds right to me but being more flexible at runtime is similar to the way we have done for dependance on other binaries. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Thu, Aug 06, 2009 at 02:37:53PM +0200, Daniel Veillard wrote:
On Thu, Aug 06, 2009 at 12:39:34PM +0100, Daniel P. Berrange wrote:
On Wed, Aug 05, 2009 at 12:58:33PM +0200, Jonas Eriksson wrote:
* src/remote_internal.c: Honour USE_SOCAT by selecting between netcat/nc and socat at compile time.
Changing the binary used at compile time is really not a good idea, because libvirt uses netcat on the remote machine, which is not required to be the same distro as the client machine on whihc you built libvirt. So by making socat vs netcat a compile time option you pretty much guarentee incompatibility between libvirt client & server betweeen distros. It is really better to fix netcat on the distros where -U isn't available.
As for other case where we had multiple binary options, isn't picking up at runtime a possibility, suppose we can catch that 'netcat -U' fails, we could try to fallback to socat. ...and /bin/nc.openbsd on Debian. Having this would be appreciated (unfortunately I don't have time to work on it). Cheers, -- Guido
In any case a compile time switch doesn't sounds right to me but being more flexible at runtime is similar to the way we have done for dependance on other binaries.
Daniel
-- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
-- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
Guido Günther
-
Jonas Eriksson