veyron/lib/testutil/integration: use SHELL env var in DebugShell impl

Change-Id: I610403696c209857f62fa03e5d498c3c7c47e075
diff --git a/lib/testutil/integration/util.go b/lib/testutil/integration/util.go
index 208fad1..b3ffd16 100644
--- a/lib/testutil/integration/util.go
+++ b/lib/testutil/integration/util.go
@@ -22,6 +22,7 @@
 package integration
 
 import (
+	"bufio"
 	"bytes"
 	"fmt"
 	"io"
@@ -322,6 +323,30 @@
 	}
 }
 
+// Tries to determine if the given shellPath represents a valid shell (i.e. is
+// present in /etc/shells).
+//
+// TODO(sjr): support platforms /etc/shells doesn't exist (e.g. windows).
+func isValidShell(shellPath string) bool {
+	f, err := os.Open("/etc/shells")
+	if err != nil {
+		return false
+	}
+	r := bufio.NewReader(f)
+	for {
+		var path string
+		if path, err = r.ReadString('\n'); err != nil {
+			break
+		}
+
+		if strings.TrimSpace(path) == shellPath {
+			return true
+		}
+	}
+
+	return false
+}
+
 func (e *integrationTestEnvironment) DebugShell() {
 	// Get the current working directory.
 	cwd, err := os.Getwd()
@@ -355,6 +380,11 @@
 	writeStringOrDie(e.t, file, fmt.Sprintf("Root mounttable endpoint: %s\n", e.RootMT()))
 
 	shellPath := "/bin/sh"
+	if shellPathFromEnv := os.Getenv("SHELL"); shellPathFromEnv != "" {
+		if isValidShell(shellPathFromEnv) {
+			shellPath = shellPathFromEnv
+		}
+	}
 	proc, err := os.StartProcess(shellPath, []string{}, &attr)
 	if err != nil {
 		e.t.Fatalf("StartProcess(%v) failed: %v", shellPath, err)