Windows: port the process helper and fix a stdin deadlock
- Tests: build VoidProcessHelper on Windows with the fork/poll-based modes compiled out, binary stdio, and a Windows fd listing; enable the ProcessStream suite there. - Process (Windows): communicate_blocking could block forever when the stdin write completed synchronously: the wait only armed pending operations, so the stdin pipe was never closed and the child never saw EOF. Complete ready operations before waiting, and report real EOF only when a read actually reached end of stream.
This commit is contained in:
1 parent
b3c959b920
commit
9f45841c7d
4 files changed
+115
-60
No files matched your search
@@ -1,5 +1,7 @@
|
||||
#include <fcntl.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <poll.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -17,6 +19,17 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
extern char** environ;
|
||||
|
||||
namespace
|
||||
@@ -194,6 +207,7 @@ int mode_ignore_sigterm(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
int mode_grandchild_ignore_sigterm(int argc, char** argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
@@ -358,6 +372,7 @@ int mode_simultaneous_io(int argc, char** argv)
|
||||
}
|
||||
return (in_read > 0 || total == 0) ? 0 : 0;
|
||||
}
|
||||
#endif // !_WIN32
|
||||
|
||||
int mode_flood(int argc, char** argv)
|
||||
{
|
||||
@@ -415,9 +430,16 @@ int mode_check_fds()
|
||||
{
|
||||
std::vector<int> open_fds;
|
||||
for (int fd = 3; fd <= 64; ++fd) {
|
||||
#if defined(_WIN32)
|
||||
const auto handle = ::_get_osfhandle(fd);
|
||||
if (handle != -1) {
|
||||
open_fds.push_back(fd);
|
||||
}
|
||||
#else
|
||||
if (::fcntl(fd, F_GETFD) != -1 || errno != EBADF) {
|
||||
open_fds.push_back(fd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (open_fds.empty()) {
|
||||
std::cout << "clean\n";
|
||||
@@ -536,6 +558,12 @@ int mode_ipc_pipe_echo()
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::ios::sync_with_stdio(false);
|
||||
#if defined(_WIN32)
|
||||
// Helpers speak over binary pipes: no CRLF translation or Ctrl-Z EOF.
|
||||
(void)_setmode(_fileno(stdin), _O_BINARY);
|
||||
(void)_setmode(_fileno(stdout), _O_BINARY);
|
||||
(void)_setmode(_fileno(stderr), _O_BINARY);
|
||||
#endif
|
||||
if (argc < 2) {
|
||||
return usage_error("missing mode");
|
||||
}
|
||||
@@ -561,6 +589,7 @@ int main(int argc, char** argv)
|
||||
if (mode == "ignore-sigterm") {
|
||||
return mode_ignore_sigterm(argc, argv);
|
||||
}
|
||||
#if !defined(_WIN32)
|
||||
if (mode == "grandchild-ignore-sigterm") {
|
||||
return mode_grandchild_ignore_sigterm(argc, argv);
|
||||
}
|
||||
@@ -570,6 +599,7 @@ int main(int argc, char** argv)
|
||||
if (mode == "simultaneous-io") {
|
||||
return mode_simultaneous_io(argc, argv);
|
||||
}
|
||||
#endif
|
||||
if (mode == "flood") {
|
||||
return mode_flood(argc, argv);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user