Merge pull request #537 from garbas/master

cygwin fixes
This commit is contained in:
Eelco Dolstra 2015-05-13 10:30:30 +02:00
commit 9233ac7c56
3 changed files with 12 additions and 10 deletions

View file

@ -20,6 +20,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/select.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>

View file

@ -13,6 +13,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <utime.h> #include <utime.h>

View file

@ -942,16 +942,16 @@ string runProgram(Path program, bool searchPath, const Strings & args,
checkInterrupt(); checkInterrupt();
/* Create a pipe. */ /* Create a pipe. */
Pipe stdout, stdin; Pipe out, in;
stdout.create(); out.create();
if (!input.empty()) stdin.create(); if (!input.empty()) in.create();
/* Fork. */ /* Fork. */
Pid pid = startProcess([&]() { Pid pid = startProcess([&]() {
if (dup2(stdout.writeSide, STDOUT_FILENO) == -1) if (dup2(out.writeSide, STDOUT_FILENO) == -1)
throw SysError("dupping stdout"); throw SysError("dupping stdout");
if (!input.empty()) { if (!input.empty()) {
if (dup2(stdin.readSide, STDIN_FILENO) == -1) if (dup2(in.readSide, STDIN_FILENO) == -1)
throw SysError("dupping stdin"); throw SysError("dupping stdin");
} }
@ -967,16 +967,16 @@ string runProgram(Path program, bool searchPath, const Strings & args,
throw SysError(format("executing %1%") % program); throw SysError(format("executing %1%") % program);
}); });
stdout.writeSide.close(); out.writeSide.close();
/* FIXME: This can deadlock if the input is too long. */ /* FIXME: This can deadlock if the input is too long. */
if (!input.empty()) { if (!input.empty()) {
stdin.readSide.close(); in.readSide.close();
writeFull(stdin.writeSide, input); writeFull(in.writeSide, input);
stdin.writeSide.close(); in.writeSide.close();
} }
string result = drainFD(stdout.readSide); string result = drainFD(out.readSide);
/* Wait for the child to finish. */ /* Wait for the child to finish. */
int status = pid.wait(true); int status = pid.wait(true);