summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-12-21 01:49:55 (GMT)
committerEvan Martin <martine@danga.com>2012-12-21 02:01:41 (GMT)
commitd8d3b2f0bdee4cd3d801bcd19bf65f91fb6760e0 (patch)
tree7b0d4c84cc5577f807387b79dece393e63d90cf3
parentbe847b38264adce9a5309c6138e5c94d4785db5a (diff)
downloadNinja-d8d3b2f0bdee4cd3d801bcd19bf65f91fb6760e0.zip
Ninja-d8d3b2f0bdee4cd3d801bcd19bf65f91fb6760e0.tar.gz
Ninja-d8d3b2f0bdee4cd3d801bcd19bf65f91fb6760e0.tar.bz2
correctly open /dev/null in subprocesses
Fixes issue #468.
-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