[gtk-vnc-devel] [PATCH] [virt-viewer] Allow cross-compilation under MinGW



This is a fairly conservative patch which enables virt-viewer to build
cross-compiled under MinGW, and probably also enables it to build on
Windows itself (though this latter thing is not tested).

The patch contains:

 - a replacement for the usleep function if it is not available

 - disables the SSH tunnel if the platform lacks fork and socketpair

It would probably be possible to reenable SSH tunnels from Windows
machines, using some special replacement code that called Create-
Process, but it's not so likely that Windows users have SSH set up.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
Read my OCaml programming blog: http://camltastic.blogspot.com/
Fedora now supports 68 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
diff -ur virt-viewer-0.0.3.orig/configure.ac virt-viewer-0.0.3.mingw/configure.ac
--- virt-viewer-0.0.3.orig/configure.ac	2008-03-10 14:49:48.000000000 +0000
+++ virt-viewer-0.0.3.mingw/configure.ac	2008-10-09 16:55:56.000000000 +0100
@@ -10,6 +10,8 @@
 AM_PROG_CC_C_O
 AC_PROG_LIBTOOL
 
+AC_CONFIG_LIBOBJ_DIR([src])
+
 AC_DEFINE([_GNU_SOURCE], [], [Enable GNU extensions])
 
 VIRT_VIEWER_COMPILE_WARNINGS(maximum)
@@ -19,6 +21,13 @@
 PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.2.0)
 PKG_CHECK_MODULES(GTKVNC, gtk-vnc-1.0 >= 0.0.1)
 
+dnl Decide if this platform can support the SSH tunnel feature.
+AC_CHECK_HEADERS([sys/socket.h sys/un.h windows.h])
+AC_CHECK_FUNCS([fork socketpair])
+
+dnl Do we need to replace the usleep function (Windows).
+AC_REPLACE_FUNCS([usleep])
+
 dnl --enable-plugin to enable the browser plugin.
 NSPR_REQUIRED=4.0.0
 FIREFOX_PLUGIN_REQUIRED=1.5.0
diff -ur virt-viewer-0.0.3.orig/src/main.c virt-viewer-0.0.3.mingw/src/main.c
--- virt-viewer-0.0.3.orig/src/main.c	2008-03-10 14:49:48.000000000 +0000
+++ virt-viewer-0.0.3.mingw/src/main.c	2008-10-09 16:59:39.000000000 +0100
@@ -32,11 +32,25 @@
 #include <libvirt/libvirt.h>
 #include <libxml/xpath.h>
 #include <libxml/uri.h>
+
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+
+#ifdef HAVE_SYS_UN_H
 #include <sys/un.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
 
 #include "viewer.h"
 
+#ifndef HAVE_USLEEP
+int usleep (unsigned int usecs);
+#endif
+
 // #define DEBUG 1
 #ifdef DEBUG
 #define DEBUG_LOG(s, ...) fprintf(stderr, (s), ## __VA_ARGS__)
@@ -716,6 +730,8 @@
 	return 0;
 }
 
+#if defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK)
+
 static int viewer_open_tunnel(const char **cmd)
 {
         int fd[2];
@@ -775,6 +791,8 @@
 	return viewer_open_tunnel(cmd);
 }
 
+#endif /* defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK) */
+
 int
 viewer_start (const char *uri, const char *name,
 	      int direct, int waitvnc, int set_verbose,
@@ -834,8 +852,10 @@
 	}
 	DEBUG_LOG("Remote host is %s and transport %s user %s\n", host, transport ? transport : "", user ? user : "");
 
+#if defined(HAVE_SOCKETPAIR) && defined(HAVE_FORK)
 	if (transport && strcasecmp(transport, "ssh") == 0 && !direct)
 		fd = viewer_open_tunnel_ssh(host, port, user, vncport);
+#endif
 
 	vnc = vnc_display_new();
 	window = viewer_build_window (VNC_DISPLAY(vnc),
diff -ur virt-viewer-0.0.3.orig/src/Makefile.am virt-viewer-0.0.3.mingw/src/Makefile.am
--- virt-viewer-0.0.3.orig/src/Makefile.am	2008-03-10 14:49:48.000000000 +0000
+++ virt-viewer-0.0.3.mingw/src/Makefile.am	2008-10-09 16:58:13.000000000 +0100
@@ -2,5 +2,5 @@
 bin_PROGRAMS = virt-viewer
 
 virt_viewer_SOURCES = main.c viewer.h
-virt_viewer_LDADD = @GTKVNC_LIBS@ @GTK2_LIBS@ @LIBXML2_LIBS@ @LIBVIRT_LIBS@
+virt_viewer_LDADD = @GTKVNC_LIBS@ @GTK2_LIBS@ @LIBXML2_LIBS@ @LIBVIRT_LIBS@ @LIBOBJS@
 virt_viewer_CFLAGS = @GTKVNC_CFLAGS@ @GTK2_CFLAGS@ @LIBXML2_CFLAGS@ @LIBVIRT_CFLAGS@ @WARN_CFLAGS@
diff -ur virt-viewer-0.0.3.orig/src/usleep.c virt-viewer-0.0.3.mingw/src/usleep.c
--- virt-viewer-0.0.3.orig/src/usleep.c	2008-10-09 17:15:00.000000000 +0100
+++ virt-viewer-0.0.3.mingw/src/usleep.c	2008-10-09 16:58:32.000000000 +0100
@@ -0,0 +1,61 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2008 Red Hat.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Richard W.M. Jones <rjones redhat com>
+ */
+
+/* Replacement usleep function, only used on platforms which lack
+ * this system or library function.
+ */
+
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+#ifdef WIN32
+
+int
+usleep (unsigned int usecs)
+{
+  unsigned int msecs = usecs / 1000;
+  if (msecs < 1)
+    Sleep (1);
+  else
+    Sleep (msecs);
+}
+
+#else
+
+int
+usleep (unsigned int usecs)
+{
+  /* This sucks, but everything has sleep and it's not
+   * really that critical how long we sleep for in the
+   * main code.
+   */
+  unsigned int secs = usecs / 1000000;
+  if (secs < 1)
+    sleep (1);
+  else
+    sleep (secs);
+}
+
+#endif


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