From 0d14fc0cbb4d3bcc6c14082d589627a470cf8b66 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 7 Dec 2007 14:56:37 +0000 Subject: [PATCH] Fri Dec 7 14:49:00 UTC 2007 Richard W.M. Jones * src/console.c, src/console.h, src/virsh.c: Disable text console on Windows. * src/libvirt.c: Use replacement getpass from Gnulib. * src/libvirt.c: Initialize Winsock before use. * src/remote_internal.c: Header file fixes for Windows. Don't fail if AI_ADDRCONFIG isn't defined. Disable unsupported stuff under Windows. * src/uuid.c: ENODATA unavailable on Windows, use EIO instead. * src/virsh.c: No uid_t / getuid on Windows. * src/virsh.c: No O_SYNC on Windows. --- ChangeLog | 13 ++++++++++++ src/console.c | 4 ++++ src/console.h | 4 ++++ src/libvirt.c | 24 ++++++++++++++++++++++ src/remote_internal.c | 48 ++++++++++++++++++++++++++++++++++++++----- src/uuid.c | 4 ++++ src/virsh.c | 26 ++++++++++++++++++++++- 7 files changed, 117 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1f5856e91..fd07a61617 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Fri Dec 7 14:49:00 UTC 2007 Richard W.M. Jones + + * src/console.c, src/console.h, src/virsh.c: Disable + text console on Windows. + * src/libvirt.c: Use replacement getpass from Gnulib. + * src/libvirt.c: Initialize Winsock before use. + * src/remote_internal.c: Header file fixes for Windows. + Don't fail if AI_ADDRCONFIG isn't defined. Disable + unsupported stuff under Windows. + * src/uuid.c: ENODATA unavailable on Windows, use EIO instead. + * src/virsh.c: No uid_t / getuid on Windows. + * src/virsh.c: No O_SYNC on Windows. + Fri Dec 7 14:47:00 UTC 2007 Richard W.M. Jones * src/internal.h: Use gnulib gettext library. Define diff --git a/src/console.c b/src/console.c index ab83fcf800..6b336d98a7 100644 --- a/src/console.c +++ b/src/console.c @@ -22,6 +22,8 @@ #include "config.h" +#ifndef __MINGW32__ + #include #include #include @@ -193,6 +195,8 @@ int vshRunConsole(const char *tty) { return ret; } +#endif /* !__MINGW32__ */ + /* * Local variables: * indent-tabs-mode: nil diff --git a/src/console.h b/src/console.h index 7f146526b8..279800d947 100644 --- a/src/console.h +++ b/src/console.h @@ -23,6 +23,8 @@ #ifndef __VIR_CONSOLE_H__ #define __VIR_CONSOLE_H__ +#ifndef __MINGW32__ + #ifdef __cplusplus extern "C" { #endif @@ -33,6 +35,8 @@ extern "C" { } #endif +#endif /* !__MINGW32__ */ + #endif /* __VIR_CONSOLE_H__ */ /* diff --git a/src/libvirt.c b/src/libvirt.c index 5a7a2eb055..2f4848e93e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -23,6 +23,11 @@ #include #include #include +#include "getpass.h" + +#if HAVE_WINSOCK2_H +#include +#endif #include "internal.h" #include "driver.h" @@ -144,6 +149,21 @@ static virConnectAuth virConnectAuthDefault = { */ virConnectAuthPtr virConnectAuthPtrDefault = &virConnectAuthDefault; +#if HAVE_WINSOCK2_H +static int +winsock_init (void) +{ + WORD winsock_version, err; + WSADATA winsock_data; + + /* http://msdn2.microsoft.com/en-us/library/ms742213.aspx */ + winsock_version = MAKEWORD (2, 2); + err = WSAStartup (winsock_version, &winsock_data); + if (err != 0) + return -1; +} +#endif + /** * virInitialize: * @@ -161,6 +181,10 @@ virInitialize(void) return(0); initialized = 1; +#if HAVE_WINSOCK2_H + if (winsock_init () == -1) return -1; +#endif + if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR)) return (-1); diff --git a/src/remote_internal.c b/src/remote_internal.c index 5a3a63d18a..8174ba54b8 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -31,15 +31,29 @@ #include #include #include -#include #include -#include #include + +#ifdef HAVE_SYS_WAIT_H +#include +#endif + +#ifdef HAVE_PWD_H +#include +#endif + +#ifdef HAVE_PATHS_H #include +#endif + +#ifndef HAVE_WINSOCK2_H +#include #include #include #include -#include +#else +#include +#endif #include #include @@ -51,9 +65,15 @@ #endif #include +#include "getaddrinfo.h" + +/* AI_ADDRCONFIG is missing on some systems. */ +#ifndef AI_ADDRCONFIG +# define AI_ADDRCONFIG 0 +#endif + #include "internal.h" #include "driver.h" -#include "getaddrinfo.h" #include "remote_internal.h" #include "remote_protocol.h" @@ -207,6 +227,7 @@ remoteFindDaemonPath(void) return NULL; } +#ifndef WIN32 /** * qemuForkDaemon: * @@ -286,7 +307,7 @@ remoteForkDaemon(virConnectPtr conn) return (0); } - +#endif enum virDrvOpenRemoteFlags { VIR_DRV_OPEN_REMOTE_RO = (1 << 0), @@ -554,6 +575,7 @@ doRemoteOpen (virConnectPtr conn, break; } +#ifndef WIN32 case trans_unix: { if (!sockname) { if (flags & VIR_DRV_OPEN_REMOTE_USER) { @@ -720,6 +742,16 @@ doRemoteOpen (virConnectPtr conn, priv->sock = sv[0]; priv->pid = pid; } +#else /* WIN32 */ + + case trans_unix: + case trans_ssh: + case trans_ext: + error (conn, VIR_ERR_INVALID_ARG, + _("transport methods unix, ssh and ext are not supported under Windows")); + +#endif /* WIN32 */ + } /* switch (transport) */ @@ -769,6 +801,7 @@ doRemoteOpen (virConnectPtr conn, gnutls_deinit (priv->session); } close (priv->sock); +#ifndef WIN32 if (priv->pid > 0) { pid_t reap; do { @@ -777,6 +810,7 @@ doRemoteOpen (virConnectPtr conn, continue; } while (reap != -1 && reap != priv->pid); } +#endif } if (priv->hostname) { @@ -808,6 +842,7 @@ remoteOpen (virConnectPtr conn, if (flags & VIR_CONNECT_RO) rflags |= VIR_DRV_OPEN_REMOTE_RO; +#if WITH_QEMU if (uri && uri->scheme && STREQ (uri->scheme, "qemu") && (!uri->server || STREQ (uri->server, "")) && @@ -822,6 +857,7 @@ remoteOpen (virConnectPtr conn, } } } +#endif memset(priv, 0, sizeof(struct private_data)); priv->magic = DEAD; @@ -1306,6 +1342,7 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv) #endif close (priv->sock); +#ifndef WIN32 if (priv->pid > 0) { pid_t reap; do { @@ -1314,6 +1351,7 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv) continue; } while (reap != -1 && reap != priv->pid); } +#endif /* Free hostname copy */ if (priv->hostname) free (priv->hostname); diff --git a/src/uuid.c b/src/uuid.c index c00a1b5a74..b2022c493a 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -36,6 +36,10 @@ #define qemudLog(level, msg...) fprintf(stderr, msg) +#ifndef ENODATA +#define ENODATA EIO +#endif + static int virUUIDGenerateRandomBytes(unsigned char *buf, int buflen) diff --git a/src/virsh.c b/src/virsh.c index 92fef77a5c..375a3c2b9a 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -202,7 +202,9 @@ typedef struct __vshControl { virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */ vshCmd *cmd; /* the current command */ char *cmdstr; /* string with command */ +#ifndef __MINGW32__ uid_t uid; /* process owner */ +#endif /* __MINGW32__ */ int imode; /* interactive mode? */ int quiet; /* quiet mode */ int debug; /* print debug messages? */ @@ -457,6 +459,8 @@ static vshCmdOptDef opts_console[] = { {NULL, 0, 0, NULL} }; +#ifndef __MINGW32__ + static int cmdConsole(vshControl * ctl, vshCmd * cmd) { @@ -506,6 +510,17 @@ cmdConsole(vshControl * ctl, vshCmd * cmd) return ret; } +#else /* __MINGW32__ */ + +static int +cmdConsole(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED) +{ + vshError (ctl, FALSE, _("console not implemented on this platform")); + return FALSE; +} + +#endif /* __MINGW32__ */ + /* * "list" command */ @@ -4508,17 +4523,21 @@ vshInit(vshControl * ctl) if (ctl->conn) return FALSE; +#ifndef __MINGW32__ ctl->uid = getuid(); +#endif vshOpenLogFile(ctl); /* set up the library error handler */ virSetErrorFunc(NULL, virshErrorHandler); +#ifndef __MINGW32__ /* Force a non-root, Xen connection to readonly */ if ((ctl->name == NULL || !strcasecmp(ctl->name, "xen")) && ctl->uid != 0) ctl->readonly = 1; +#endif ctl->conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault, @@ -4537,6 +4556,11 @@ vshInit(vshControl * ctl) return TRUE; } +#ifndef O_SYNC +#define O_SYNC 0 +#endif +#define LOGFILE_FLAGS (O_WRONLY | O_APPEND | O_CREAT | O_SYNC) + /** * vshOpenLogFile: * @@ -4566,7 +4590,7 @@ vshOpenLogFile(vshControl *ctl) } /* log file open */ - if ((ctl->log_fd = open(ctl->logfile, O_WRONLY | O_APPEND | O_CREAT | O_SYNC, FILE_MODE)) < 0) { + if ((ctl->log_fd = open(ctl->logfile, LOGFILE_FLAGS, FILE_MODE)) < 0) { vshError(ctl, TRUE, _("failed to open the log file. check the log file path")); } }