summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/subprocess-posix.cc2
-rw-r--r--src/subprocess_test.cc15
2 files changed, 16 insertions, 1 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index 1c47fd1..8f1a04e 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -76,7 +76,7 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
break;
// Open /dev/null over stdin.
- int devnull = open("/dev/null", O_WRONLY);
+ int devnull = open("/dev/null", O_RDONLY);
if (devnull < 0)
break;
if (dup2(devnull, 0) < 0)
diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc
index d89525e..313b227 100644
--- a/src/subprocess_test.cc
+++ b/src/subprocess_test.cc
@@ -179,3 +179,18 @@ TEST_F(SubprocessTest, SetWithLots) {
ASSERT_EQ(kNumProcs, subprocs_.finished_.size());
}
#endif // linux
+
+// TODO: this test could work on Windows, just not sure how to simply
+// read stdin.
+#ifndef _WIN32
+// Verify that a command that attempts to read stdin correctly thinks
+// that stdin is closed.
+TEST_F(SubprocessTest, ReadStdin) {
+ Subprocess* subproc = subprocs_.Add("cat -");
+ while (!subproc->Done()) {
+ subprocs_.DoWork();
+ }
+ ASSERT_EQ(ExitSuccess, subproc->Finish());
+ ASSERT_EQ(1u, subprocs_.finished_.size());
+}
+#endif // _WIN32