* 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 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
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)
CYGWIN_EXTRA_LDFLAGS=
CYGWIN_EXTRA_LIBADD=
CYGWIN_EXTRA_PYTHON_LIBADD=
+MINGW_EXTRA_LDFLAGS=
case "$host" in
*-*-cygwin*)
CYGWIN_EXTRA_LDFLAGS="-no-undefined"
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
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 \
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
#include <libxml/uri.h>
#include "getpass.h"
-#if HAVE_WINSOCK2_H
+#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
* Utility functions to help parse and assemble query strings.
*/
+#include <config.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#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>
#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>
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;
}
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;
}
__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)
__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)
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;
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) {
--- /dev/null
+/*\r
+ * socketcompat.h: Socket compatibility for Windows, making it slightly\r
+ * less painful to use.\r
+ *\r
+ * Use this header under the following circumstances:\r
+ * (a) Instead of including any of: <net/if.h>, <netinet/in.h>,\r
+ * <sys/socket.h>, <netdb.h>, <netinet/tcp.h>, AND\r
+ * (b) The file will be part of what is built on Windows (basically\r
+ * just remote client stuff).\r
+ *\r
+ * You need to use socket_errno() instead of errno to get socket\r
+ * errors.\r
+ *\r
+ * Copyright (C) 2008 Red Hat, Inc.\r
+ *\r
+ * See COPYING.LIB for the License of this software\r
+ *\r
+ * Richard W.M. Jones <rjones@redhat.com>\r
+ */\r
+\r
+#ifndef __SOCKETCOMPAT_H__\r
+#define __SOCKETCOMPAT_H__\r
+\r
+#include <config.h>\r
+\r
+#include <errno.h>\r
+\r
+#ifndef HAVE_WINSOCK2_H /* Unix & Cygwin. */\r
+\r
+#include <sys/socket.h>\r
+#include <net/if.h>\r
+#include <netinet/in.h>\r
+#include <netinet/tcp.h>\r
+\r
+static inline int\r
+socket_errno (void)\r
+{\r
+ return errno;\r
+}\r
+\r
+#else /* MinGW & Win32 */\r
+\r
+#include <winsock2.h>\r
+\r
+/* Socket functions in Windoze don't set errno. Instead of using errno\r
+ * to test for socket errors, call this function to get the errno.\r
+ */\r
+static inline int\r
+socket_errno (void)\r
+{\r
+ return WSAGetLastError ();\r
+}\r
+\r
+/* Compatibility. */\r
+#define EWOULDBLOCK WSAEWOULDBLOCK\r
+#define ECONNREFUSED WSAECONNREFUSED\r
+\r
+#endif /* HAVE_WINSOCK2_H */\r
+\r
+#endif /* __WINSOCKWRAPPER_H__ */\r
#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>
#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"