Skip to content
Browse files

correctly open /dev/null in subprocesses

Fixes issue #468.
  • Loading branch information...
1 parent be847b3 commit d8d3b2f0bdee4cd3d801bcd19bf65f91fb6760e0 @martine martine committed
Showing with 16 additions and 1 deletion.
  1. +1 −1 src/subprocess-posix.cc
  2. +15 −0 src/subprocess_test.cc
View
2 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)
View
15 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

0 comments on commit d8d3b2f

Please sign in to comment.
Something went wrong with that request. Please try again.