#include <config.h>
-#include <poll.h>
+#ifndef WIN32
+# include <poll.h>
+#endif
#include <signal.h>
#include <stdarg.h>
#include <sys/stat.h>
-#include <sys/wait.h>
+#ifndef WIN32
+# include <sys/wait.h>
+#endif
#include <fcntl.h>
#include <unistd.h>
static virBufferPtr dryRunBuffer;
static virCommandDryRunCallback dryRunCallback;
static void *dryRunOpaque;
+#ifndef WIN32
static int dryRunStatus;
+#endif /* !WIN32 */
/*
* virCommandFDIsSet:
return 0;
}
+
/*
* virExec:
* @cmd virCommandPtr containing all information about the program to
return -1;
}
+
/**
* virRun:
* @argv NULL terminated argv to run
return -1;
}
-static int
-virExec(virCommandPtr cmd G_GNUC_UNUSED)
-{
- /* XXX: Some day we can implement pieces of virCommand/virExec on
- * top of _spawn() or CreateProcess(), but we can't implement
- * everything, since mingw completely lacks fork(), so we cannot
- * run our own code in the child process. */
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("virExec is not implemented for WIN32"));
- return -1;
-}
-
pid_t
virFork(void)
{
}
+#ifndef WIN32
/**
* virCommandSetSendBuffer
* @cmd: the command to modify
* given file descriptor. The buffer will be freed automatically
* and the file descriptor closed.
*/
-#if defined(F_SETFL)
int
virCommandSetSendBuffer(virCommandPtr cmd,
int fd,
return 0;
}
-#else /* !defined(F_SETFL) */
-
-int
-virCommandSetSendBuffer(virCommandPtr cmd,
- int fd G_GNUC_UNUSED,
- unsigned char *buffer G_GNUC_UNUSED,
- size_t buflen G_GNUC_UNUSED)
-{
- if (!cmd || cmd->has_error)
- return -1;
-
- cmd->has_error = ENOTSUP;
-
- return -1;
-}
-
-#endif
static int
virCommandSendBuffersFillPollfd(virCommandPtr cmd,
return 0;
}
+#endif /* !WIN32 */
+
+
/**
* virCommandSetInputBuffer:
* @cmd: the command to modify
}
+#ifndef WIN32
/*
* Manage input and output to the child process.
*/
* Returns -1 on any error executing the command.
* Will not return on success.
*/
-#ifndef WIN32
int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups)
{
if (!cmd ||cmd->has_error == ENOMEM) {
cmd->args[0]);
return -1;
}
-#else
-int virCommandExec(virCommandPtr cmd G_GNUC_UNUSED, gid_t *groups G_GNUC_UNUSED,
- int ngroups G_GNUC_UNUSED)
-{
- /* Mingw execve() has a broken signature. Disable this
- * function until gnulib fixes the signature, since we
- * don't really need this on Win32 anyway.
- */
- virReportSystemError(ENOSYS, "%s",
- _("Executing new processes is not supported on Win32 platform"));
- return -1;
-}
-#endif
+
/**
* virCommandRun:
}
cmd->infd = infd[0];
cmd->inpipe = infd[1];
-#if defined (F_SETFL)
+
if (fcntl(cmd->inpipe, F_SETFL, O_NONBLOCK) < 0) {
virReportSystemError(errno, "%s",
_("fcntl failed to set O_NONBLOCK"));
ret = -1;
goto cleanup;
}
-#else /* !defined(F_SETFL) */
- cmd->has_error = ENOTSUP;
- ret = -1;
- goto cleanup;
-#endif
} else if ((cmd->inbuf && cmd->infd == -1) ||
(cmd->outbuf && cmd->outfdptr != &cmd->outfd) ||
(cmd->errbuf && cmd->errfdptr != &cmd->errfd)) {
}
-#ifndef WIN32
/**
* virCommandAbort:
* @cmd: command to abort
cmd->pid = -1;
cmd->reap = false;
}
-#else /* WIN32 */
-void
-virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED)
-{
- /* Mingw lacks WNOHANG and kill(). But since we haven't ported
- * virExec to mingw yet, there's no process to be killed,
- * making this implementation trivially correct for now :) */
-}
-#endif
/**
VIR_FORCE_CLOSE(cmd->handshakeNotify[1]);
return 0;
}
+#else /* WIN32 */
+int
+virCommandSetSendBuffer(virCommandPtr cmd,
+ int fd G_GNUC_UNUSED,
+ unsigned char *buffer G_GNUC_UNUSED,
+ size_t buflen G_GNUC_UNUSED)
+{
+ if (!cmd || cmd->has_error)
+ return -1;
+
+ cmd->has_error = ENOTSUP;
+
+ return -1;
+}
+
+
+int
+virCommandExec(virCommandPtr cmd G_GNUC_UNUSED, gid_t *groups G_GNUC_UNUSED,
+ int ngroups G_GNUC_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Executing new processes is not supported on Win32 platform"));
+ return -1;
+}
+
+
+int
+virCommandRun(virCommandPtr cmd G_GNUC_UNUSED, int *exitstatus G_GNUC_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Executing new processes is not supported on Win32 platform"));
+ return -1;
+}
+
+
+int
+virCommandRunAsync(virCommandPtr cmd G_GNUC_UNUSED, pid_t *pid G_GNUC_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Executing new processes is not supported on Win32 platform"));
+ return -1;
+}
+
+
+int
+virCommandWait(virCommandPtr cmd G_GNUC_UNUSED, int *exitstatus G_GNUC_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Executing new processes is not supported on Win32 platform"));
+ return -1;
+}
+
+
+void
+virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED)
+{
+ /* Mingw lacks WNOHANG and kill(). But since we haven't ported
+ * virExec to mingw yet, there's no process to be killed,
+ * making this implementation trivially correct for now :) */
+}
+
+
+void virCommandRequireHandshake(virCommandPtr cmd)
+{
+ if (!cmd || cmd->has_error)
+ return;
+
+ cmd->has_error = ENOSYS;
+}
+
+
+int virCommandHandshakeWait(virCommandPtr cmd G_GNUC_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Executing new processes is not supported on Win32 platform"));
+ return -1;
+}
+
+
+int virCommandHandshakeNotify(virCommandPtr cmd G_GNUC_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Executing new processes is not supported on Win32 platform"));
+ return -1;
+}
+#endif /* WIN32 */
/**