Commit a65bce17 authored by Kenton Varda's avatar Kenton Varda

Make sure capnpc plugins on Windows get a proper EOF.

On Windows, we don't have `fork()` and `exec()`, but rather `spawn()`, which does both in one call. This makes FD inheritance hard -- the parent process has to set up its own FD table to be what it wants the child to receive, then call spawn(), then set things back.

`capnp` does all that, but there was a problem: when it created a pipe, it failed to set the FDs as non-inheritable (Windows equivalent of CLOEXEC). Thus the child would implicitly inherit both ends of the pipe without knowing it. Since it would never close the write end, it would never receive EOF on the read end.

The fix turns out to be simple: create the pipe non-inheritable. We are already separately using `dup2()` to create the copy of the descriptor that we actually want inherited.

Fixes #488.
parent 86c8498c
......@@ -100,7 +100,7 @@ using ::close;
// We're on Windows, including MinGW. pipe() and mkdir() are non-standard even on MinGW.
inline int pipe(int fds[2]) {
return ::_pipe(fds, 8192, _O_BINARY);
return ::_pipe(fds, 8192, _O_BINARY | _O_NOINHERIT);
}
inline int mkdir(const char* path, int mode) {
return ::_mkdir(path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment