[PATCH xorg-gtest 02/11] process: add XORG_GTEST_CHILD_STDOUT environment variable

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 15 23:36:35 PDT 2012


If this variable is set, leave stdout and stderr open for the child process
to see potential error messages thrown by that child.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 README          | 3 +++
 src/process.cpp | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/README b/README
index 33e1fe3..bda4b66 100644
--- a/README
+++ b/README
@@ -79,3 +79,6 @@ Environment variables
 ---------------------
 XORG_GTEST_XSERVER_SIGSTOP
   If set, an XServer object will raise a SIGSTOP signal after startup.
+XORG_GTEST_CHILD_STDOUT
+  If set to any value, Process::Start() will _not_ close stdout/stdin/stderr
+  for the forked child.
diff --git a/src/process.cpp b/src/process.cpp
index 7df2b84..03dbc42 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -58,8 +58,10 @@ void xorg::testing::Process::Start(const std::string &program, const std::vector
     throw std::runtime_error("Failed to fork child process");
   } else if (d_->pid == 0) { /* Child */
     close(0);
-    close(1);
-    close(2);
+    if (getenv("XORG_GTEST_CHILD_STDOUT") == NULL) {
+      close(1);
+      close(2);
+    }
 
     std::vector<char*> args;
     std::vector<std::string>::const_iterator it;
-- 
1.7.11.2



More information about the xorg-devel mailing list