#include <boost/bind.hpp>
+#include <vector>
#include <cerrno>
-#include <csignal>
-#include <cstdlib>
-#include <sys/types.h>
-#include <sys/wait.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#include <vector>
+#ifdef _WIN32
+# define SIGHUP 1
+# define SIGKILL 9
+# include <process.h>
+# include <windows.h>
+
+#else
+# include <csignal>
+# include <cstdlib>
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+# include <sys/wait.h>
+#endif
using std::endl;
using std::string;
if (!pid())
return false;
+#if !defined (_WIN32)
// Un-UNIX like, but we don't have much use for
// knowing if a zombie exists, so just reap it first.
int waitstatus;
waitpid(pid(), &waitstatus, WNOHANG);
+#endif
// Racy of course, but it will do.
if (lyx::support::kill(pid(), 0) && errno == ESRCH)
return;
}
- int const tolerance = std::max(0, tol);
+ // The weird (std::max)(a,b) signature prevents expansion
+ // of an evil MSVC macro.
+ int const tolerance = (std::max)(0, tol);
if (tolerance == 0) {
// Kill it dead NOW!
Murder::killItDead(0, pid());
{
// We'll pretend that the child returns 1 on all error conditions.
retval_ = 1;
+
+#if defined (_WIN32)
+ HANDLE const hProcess = HANDLE(pid_);
+
+ DWORD const wait_status = ::WaitForSingleObject(hProcess, INFINITE);
+
+ switch (wait_status) {
+ case WAIT_OBJECT_0: {
+ DWORD exit_code = 0;
+ if (!GetExitCodeProcess(hProcess, &exit_code)) {
+ lyxerr << "GetExitCodeProcess failed waiting for child\n"
+ << getChildErrorMessage() << std::endl;
+ } else
+ retval_ = exit_code;
+ break;
+ }
+ case WAIT_FAILED:
+ lyxerr << "WaitForSingleObject failed waiting for child\n"
+ << getChildErrorMessage() << std::endl;
+ break;
+ }
+
+#else
int status;
bool wait = true;
while (wait) {
wait = false;
}
}
+#endif
return retval_;
}
if (c == ' ')
*it = '\0';
else if (c == '\'' || c == '"') {
+#if defined (_WIN32)
+ // How perverse!
+ // spawnvp *requires* the quotes or it will
+ // split the arg at the internal whitespace!
+ // Make shure the quote is a DOS-style one.
+ *it = '"';
+#else
*it = '\0';
+#endif
inside_quote = c;
}
} else if (c == inside_quote) {
+#if defined (_WIN32)
+ *it = '"';
+#else
*it = '\0';
+#endif
inside_quote = 0;
}
}
argv.push_back(0);
// Debug output.
- vector<char *>::iterator ait = argv.begin();
- vector<char *>::iterator const aend = argv.end();
- lyxerr << "<command>\n";
- for (; ait != aend; ++ait)
- if (*ait)
- lyxerr << '\t'<< *ait << '\n';
- lyxerr << "</command>" << std::endl;
-
-#ifndef __EMX__
+ if (lyxerr.debugging(Debug::FILES)) {
+ vector<char *>::iterator ait = argv.begin();
+ vector<char *>::iterator const aend = argv.end();
+ lyxerr << "<command>\n\t" << line
+ << "\n\tInterpretted as:\n\n";
+ for (; ait != aend; ++ait)
+ if (*ait)
+ lyxerr << '\t'<< *ait << '\n';
+ lyxerr << "</command>" << std::endl;
+ }
+
+#ifdef _WIN32
+ pid_t const cpid = spawnvp(_P_NOWAIT, argv[0], &*argv.begin());
+#else // POSIX
pid_t const cpid = ::fork();
if (cpid == 0) {
// Child
<< strerror(errno) << endl;
_exit(1);
}
-#else
- pid_t const cpid = spawnvp(P_SESSION|P_DEFAULT|P_MINIMIZE|P_BACKGROUND,
- argv[0], &*argv.begin());
#endif
if (cpid < 0) {