lib/testutil/integration: use /dev/tty as DebugShell stdout

Previously, if the user did not specify "-v" in "v23 go test", tests
using DebugShell would appear to hang. In fact, the debug shell was
waiting for input from stdin, but the user would never know this because
stdout was redirected to /dev/null.

Change-Id: I17a6fcdf7e797fe1ad9e376adcfa9665c853cd11
diff --git a/lib/testutil/integration/util.go b/lib/testutil/integration/util.go
index 6c4b185..81e148a 100644
--- a/lib/testutil/integration/util.go
+++ b/lib/testutil/integration/util.go
@@ -221,6 +221,13 @@
 	}
 }
 
+func writeStringOrDie(t *testing.T, f *os.File, s string) {
+	_, err := f.WriteString(s)
+	if err != nil {
+		t.Fatalf("Write() failed: %v", err)
+	}
+}
+
 func (e *integrationTestEnvironment) DebugShell() {
 	// Get the current working directory.
 	cwd, err := os.Getwd()
@@ -231,26 +238,27 @@
 	// Transfer stdin, stdout, and stderr to the new process
 	// and also set target directory for the shell to start in.
 	dev := "/dev/tty"
-	fd, err := syscall.Open(dev, 0, 0)
+	fd, err := syscall.Open(dev, syscall.O_RDWR, 0)
 	if err != nil {
-		e.t.Logf("WARNING: Open(%v) failed, not going to create a debug shell: %v", dev, err)
+		e.t.Logf("WARNING: Open(%v) failed, was asked to create a debug shell but cannot: %v", dev, err)
 		return
 	}
+	file := os.NewFile(uintptr(fd), dev)
 	attr := os.ProcAttr{
-		Files: []*os.File{os.NewFile(uintptr(fd), "/dev/tty"), os.Stdout, os.Stderr},
+		Files: []*os.File{file, file, file},
 		Dir:   cwd,
 	}
 
 	// Start up a new shell.
-	fmt.Printf(">> Starting a new interactive shell\n")
-	fmt.Printf("Hit CTRL-D to resume the test\n")
+	writeStringOrDie(e.t, file, ">> Starting a new interactive shell\n")
+	writeStringOrDie(e.t, file, "Hit CTRL-D to resume the test\n")
 	if len(e.builtBinaries) > 0 {
-		fmt.Println("Built binaries:")
+		writeStringOrDie(e.t, file, "Built binaries:")
 		for _, value := range e.builtBinaries {
-			fmt.Println(value.Path())
+			writeStringOrDie(e.t, file, value.Path()+"\n")
 		}
 	}
-	fmt.Println("Root mounttable endpoint:", e.RootMT())
+	writeStringOrDie(e.t, file, fmt.Sprintf("Root mounttable endpoint: %s\n", e.RootMT()))
 
 	shellPath := "/bin/sh"
 	proc, err := os.StartProcess(shellPath, []string{}, &attr)
@@ -264,7 +272,7 @@
 		e.t.Fatalf("Wait(%v) failed: %v", shellPath, err)
 	}
 
-	fmt.Printf("<< Exited shell: %s\n", state.String())
+	writeStringOrDie(e.t, file, fmt.Sprintf("<< Exited shell: %s\n", state.String()))
 }
 
 func (e *integrationTestEnvironment) BuildGoPkg(binary_path string) TestBinary {