diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2008-01-05 16:06:36 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2008-01-05 16:06:36 +0000 |
commit | 029aef1d241564f510ea7d1cef888f3e2319d687 (patch) | |
tree | 5d46c7f52e697e95eef81130ec98b1e6e27be42f | |
parent | Fix crash when no auth callback is provided (diff) | |
download | libvirt-029aef1d241564f510ea7d1cef888f3e2319d687.tar.gz libvirt-029aef1d241564f510ea7d1cef888f3e2319d687.tar.bz2 libvirt-029aef1d241564f510ea7d1cef888f3e2319d687.zip |
Miscellaneous fixes for building on Windows (MinGW).
* configure.in: xdr functions may require -lxdr.
* configure.in, src/Makefile.am: Extra linking flags for
building libvirt DLL.
* src/socketcompat.h: Hide Windows Winsock incompatibilities
in a separate header file.
* src/remote_internal.c: Switch to using socketcompat.h /
socket_errno().
* src/test.c: Switch to using socketcompat.h.
* gnulib/lib/arpa/.cvsignore: Ignore another generated file.
* src/qparams.c: Include <config.h>.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | configure.in | 9 | ||||
-rw-r--r-- | gnulib/lib/arpa/.cvsignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/libvirt.c | 2 | ||||
-rw-r--r-- | src/qparams.c | 2 | ||||
-rw-r--r-- | src/remote_internal.c | 35 | ||||
-rw-r--r-- | src/socketcompat.h | 60 | ||||
-rw-r--r-- | src/test.c | 8 |
9 files changed, 103 insertions, 31 deletions
@@ -1,3 +1,17 @@ +Wed Jan 5 16:02:00 UTC 2008 Richard W.M. Jones <rjones@redhat.com> + + Miscellaneous fixes for building on Windows (MinGW). + * configure.in: xdr functions may require -lxdr. + * configure.in, src/Makefile.am: Extra linking flags for + building libvirt DLL. + * src/socketcompat.h: Hide Windows Winsock incompatibilities + in a separate header file. + * src/remote_internal.c: Switch to using socketcompat.h / + socket_errno(). + * src/test.c: Switch to using socketcompat.h. + * gnulib/lib/arpa/.cvsignore: Ignore another generated file. + * src/qparams.c: Include <config.h>. + Wed Jan 2 17:45:53 EST 2008 Daniel P. Berrange <berrange@redhat.com> * src/remote_internal.c: fix policykit auth handling of NULL diff --git a/configure.in b/configure.in index 26db6214e..bc56c2c30 100644 --- a/configure.in +++ b/configure.in @@ -65,8 +65,8 @@ AC_CHECK_FUNCS([cfmakeraw regexec uname]) dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([pwd.h paths.h sys/syslimits.h sys/utsname.h sys/wait.h winsock2.h]) -dnl Need -lrpc? (Cygwin needs this) -AC_SEARCH_LIBS(xdrmem_create,rpc) +dnl Need -lrpc or -lxdr? (Cygwin and MinGW resp. need this) +AC_SEARCH_LIBS(xdrmem_create,[rpc xdr]) dnl Do we have rpcgen? AC_PATH_PROG(RPCGEN, rpcgen, no) @@ -650,6 +650,7 @@ dnl for now since I'm not supporting mingw at present. - RWMJ CYGWIN_EXTRA_LDFLAGS= CYGWIN_EXTRA_LIBADD= CYGWIN_EXTRA_PYTHON_LIBADD= +MINGW_EXTRA_LDFLAGS= case "$host" in *-*-cygwin*) CYGWIN_EXTRA_LDFLAGS="-no-undefined" @@ -658,10 +659,14 @@ case "$host" in CYGWIN_EXTRA_PYTHON_LIBADD="-L/usr/lib/python${PYTHON_VERSION}/config -lpython${PYTHON_VERSION}" fi ;; + *-*-mingw*) + MINGW_EXTRA_LDFLAGS="-no-undefined" + ;; esac AC_SUBST(CYGWIN_EXTRA_LDFLAGS) AC_SUBST(CYGWIN_EXTRA_LIBADD) AC_SUBST(CYGWIN_EXTRA_PYTHON_LIBADD) +AC_SUBST(MINGW_EXTRA_LDFLAGS) # very annoying rm -f COPYING diff --git a/gnulib/lib/arpa/.cvsignore b/gnulib/lib/arpa/.cvsignore index e69de29bb..b9013ae26 100644 --- a/gnulib/lib/arpa/.cvsignore +++ b/gnulib/lib/arpa/.cvsignore @@ -0,0 +1 @@ +inet.h diff --git a/src/Makefile.am b/src/Makefile.am index 82194485a..d058465ab 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ lib_LTLIBRARIES = libvirt.la CLIENT_SOURCES = \ libvirt.c internal.h \ gnutls_1_0_compat.h \ + socketcompat.h \ hash.c hash.h \ test.c test.h \ buf.c buf.h \ @@ -68,7 +69,7 @@ libvirt_la_LIBADD = $(LIBXML_LIBS) $(GNUTLS_LIBS) $(SASL_LIBS) \ libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \ -version-info @LIBVIRT_VERSION_INFO@ \ $(COVERAGE_CFLAGS:-f%=-Wc,-f%) \ - @CYGWIN_EXTRA_LDFLAGS@ + @CYGWIN_EXTRA_LDFLAGS@ @MINGW_EXTRA_LDFLAGS@ libvirt_la_CFLAGS = $(COVERAGE_CFLAGS) bin_PROGRAMS = virsh diff --git a/src/libvirt.c b/src/libvirt.c index 67d7e18c2..ca38c5475 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -25,7 +25,7 @@ #include <libxml/uri.h> #include "getpass.h" -#if HAVE_WINSOCK2_H +#ifdef HAVE_WINSOCK2_H #include <winsock2.h> #endif diff --git a/src/qparams.c b/src/qparams.c index 526c50e63..1c06fb1a4 100644 --- a/src/qparams.c +++ b/src/qparams.c @@ -20,6 +20,8 @@ * Utility functions to help parse and assemble query strings. */ +#include <config.h> + #include <stdio.h> #include <stdlib.h> #include <stdarg.h> diff --git a/src/remote_internal.c b/src/remote_internal.c index a18468598..d9d4ba95f 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -23,12 +23,14 @@ #include "config.h" +/* Windows socket compatibility functions. */ +#include "socketcompat.h" + #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <assert.h> -#include <errno.h> #include <signal.h> #include <sys/types.h> #include <sys/stat.h> @@ -46,15 +48,6 @@ #include <paths.h> #endif -#ifndef HAVE_WINSOCK2_H -#include <sys/socket.h> -#include <netdb.h> -#include <netinet/in.h> -#include <netinet/tcp.h> -#else -#include <winsock2.h> -#endif - #include <rpc/types.h> #include <rpc/xdr.h> #include <gnutls/gnutls.h> @@ -525,7 +518,7 @@ doRemoteOpen (virConnectPtr conn, priv->sock = socket (r->ai_family, SOCK_STREAM, 0); if (priv->sock == -1) { - error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + error (conn, VIR_ERR_SYSTEM_ERROR, strerror (socket_errno ())); continue; } @@ -535,7 +528,7 @@ doRemoteOpen (virConnectPtr conn, sizeof no_slow_start); if (connect (priv->sock, r->ai_addr, r->ai_addrlen) == -1) { - error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); + error (conn, VIR_ERR_SYSTEM_ERROR, strerror (socket_errno ())); close (priv->sock); continue; } @@ -3036,7 +3029,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open, __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE, VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "failed to get sock address %d (%s)", - errno, strerror(errno)); + socket_errno (), strerror(socket_errno ())); goto cleanup; } if ((localAddr = addrToString(&sa, salen)) == NULL) @@ -3048,7 +3041,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open, __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE, VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "failed to get peer address %d (%s)", - errno, strerror(errno)); + socket_errno (), strerror(socket_errno ())); goto cleanup; } if ((remoteAddr = addrToString(&sa, salen)) == NULL) @@ -3601,12 +3594,13 @@ really_write_buf (virConnectPtr conn, struct private_data *priv, while (len > 0); } else { do { - err = write (priv->sock, p, len); + err = send (priv->sock, p, len, 0); if (err == -1) { - if (errno == EINTR || errno == EAGAIN) + int errno_ = socket_errno (); + if (errno_ == EINTR || errno_ == EAGAIN) continue; error (in_open ? NULL : conn, - VIR_ERR_SYSTEM_ERROR, strerror (errno)); + VIR_ERR_SYSTEM_ERROR, strerror (errno_)); return -1; } len -= err; @@ -3683,12 +3677,13 @@ really_read_buf (virConnectPtr conn, struct private_data *priv, return err; } else { reread: - err = read (priv->sock, bytes, len); + err = recv (priv->sock, bytes, len, 0); if (err == -1) { - if (errno == EINTR) + int errno_ = socket_errno (); + if (errno_ == EINTR) goto reread; error (in_open ? NULL : conn, - VIR_ERR_SYSTEM_ERROR, strerror (errno)); + VIR_ERR_SYSTEM_ERROR, strerror (errno_)); return -1; } if (err == 0) { diff --git a/src/socketcompat.h b/src/socketcompat.h new file mode 100644 index 000000000..0a8884cb5 --- /dev/null +++ b/src/socketcompat.h @@ -0,0 +1,60 @@ +/*
+ * socketcompat.h: Socket compatibility for Windows, making it slightly
+ * less painful to use.
+ *
+ * Use this header under the following circumstances:
+ * (a) Instead of including any of: <net/if.h>, <netinet/in.h>,
+ * <sys/socket.h>, <netdb.h>, <netinet/tcp.h>, AND
+ * (b) The file will be part of what is built on Windows (basically
+ * just remote client stuff).
+ *
+ * You need to use socket_errno() instead of errno to get socket
+ * errors.
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Richard W.M. Jones <rjones@redhat.com>
+ */
+
+#ifndef __SOCKETCOMPAT_H__
+#define __SOCKETCOMPAT_H__
+
+#include <config.h>
+
+#include <errno.h>
+
+#ifndef HAVE_WINSOCK2_H /* Unix & Cygwin. */
+
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+static inline int
+socket_errno (void)
+{
+ return errno;
+}
+
+#else /* MinGW & Win32 */
+
+#include <winsock2.h>
+
+/* Socket functions in Windoze don't set errno. Instead of using errno
+ * to test for socket errors, call this function to get the errno.
+ */
+static inline int
+socket_errno (void)
+{
+ return WSAGetLastError ();
+}
+
+/* Compatibility. */
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define ECONNREFUSED WSAECONNREFUSED
+
+#endif /* HAVE_WINSOCK2_H */
+
+#endif /* __WINSOCKWRAPPER_H__ */
diff --git a/src/test.c b/src/test.c index 825707ce8..d228b3196 100644 --- a/src/test.c +++ b/src/test.c @@ -28,7 +28,6 @@ #include <stdio.h> #include <string.h> #include <sys/time.h> -#include <errno.h> #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xpath.h> @@ -37,12 +36,7 @@ #include <unistd.h> #include <sys/stat.h> -#ifndef HAVE_WINSOCK2_H -#include <net/if.h> -#include <netinet/in.h> -#else -#include <winsock2.h> -#endif +#include "socketcompat.h" #include "internal.h" #include "test.h" |