Browse code

Merge pull request #7083 from mheon/6983_bugfix

Fix Panic with -t and -a stderr

Victor Vieux authored on 2014/07/18 10:41:24
Showing 2 changed files
... ...
@@ -88,7 +88,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
88 88
 			}()
89 89
 
90 90
 			// When TTY is ON, use regular copy
91
-			if setRawTerminal {
91
+			if setRawTerminal && stdout != nil {
92 92
 				_, err = io.Copy(stdout, br)
93 93
 			} else {
94 94
 				_, err = utils.StdCopy(stdout, stderr, br)
... ...
@@ -1247,3 +1247,51 @@ func TestDnsOptionsBasedOnHostResolvConf(t *testing.T) {
1247 1247
 
1248 1248
 	logDone("run - dns options based on host resolv.conf")
1249 1249
 }
1250
+
1251
+// Regression test for #6983
1252
+func TestAttachStdErrOnlyTTYMode(t *testing.T) {
1253
+	cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stderr", "busybox", "true")
1254
+
1255
+	exitCode, err := runCommand(cmd)
1256
+	if err != nil {
1257
+		t.Fatal(err)
1258
+	} else if exitCode != 0 {
1259
+		t.Fatalf("Container should have exited with error code 0")
1260
+	}
1261
+
1262
+	deleteAllContainers()
1263
+
1264
+	logDone("run - Attach stderr only with -t")
1265
+}
1266
+
1267
+// Regression test for #6983
1268
+func TestAttachStdOutOnlyTTYMode(t *testing.T) {
1269
+	cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stdout", "busybox", "true")
1270
+
1271
+	exitCode, err := runCommand(cmd)
1272
+	if err != nil {
1273
+		t.Fatal(err)
1274
+	} else if exitCode != 0 {
1275
+		t.Fatalf("Container should have exited with error code 0")
1276
+	}
1277
+
1278
+	deleteAllContainers()
1279
+
1280
+	logDone("run - Attach stdout only with -t")
1281
+}
1282
+
1283
+// Regression test for #6983
1284
+func TestAttachStdOutAndErrTTYMode(t *testing.T) {
1285
+	cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stdout", "-a", "stderr", "busybox", "true")
1286
+
1287
+	exitCode, err := runCommand(cmd)
1288
+	if err != nil {
1289
+		t.Fatal(err)
1290
+	} else if exitCode != 0 {
1291
+		t.Fatalf("Container should have exited with error code 0")
1292
+	}
1293
+
1294
+	deleteAllContainers()
1295
+
1296
+	logDone("run - Attach stderr and stdout with -t")
1297
+}