[libvirt] [PATCH] Support the usage of socat instead of netcat

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

 



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/libvirt-0.4.6-11.1.src.rpm

* 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

--
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]