Explorar o código

Merge pull request #4942 from vieux/cleanup_dev_libcontainer

remove setupDev from libcontainer
Michael Crosby %!s(int64=11) %!d(string=hai) anos
pai
achega
9cf89f8542
Modificáronse 2 ficheiros con 25 adicións e 27 borrados
  1. 25 0
      integration-cli/docker_cli_diff_test.go
  2. 0 27
      pkg/libcontainer/nsinit/mount.go

+ 25 - 0
integration-cli/docker_cli_diff_test.go

@@ -64,3 +64,28 @@ func TestDiffEnsureDockerinitFilesAreIgnored(t *testing.T) {
 
 	logDone("diff - check if ignored files show up in diff")
 }
+
+func TestDiffEnsureOnlyKmsgAndPtmx(t *testing.T) {
+	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep 0")
+	cid, _, err := runCommandWithOutput(runCmd)
+	errorOut(err, t, fmt.Sprintf("%s", err))
+	cleanCID := stripTrailingCharacters(cid)
+
+	diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
+	out, _, err := runCommandWithOutput(diffCmd)
+	errorOut(err, t, fmt.Sprintf("failed to run diff: %v %v", out, err))
+	go deleteContainer(cleanCID)
+
+	expected := map[string]bool{
+		"C /dev":      true,
+		"A /dev/full": true, // busybox
+		"C /dev/ptmx": true, // libcontainer
+		"A /dev/kmsg": true, // lxc
+	}
+
+	for _, line := range strings.Split(out, "\n") {
+		if line != "" && !expected[line] {
+			t.Errorf("'%s' is shown in the diff but shouldn't", line)
+		}
+	}
+}

+ 0 - 27
pkg/libcontainer/nsinit/mount.go

@@ -57,9 +57,6 @@ func setupNewMountNamespace(rootfs string, bindMounts []libcontainer.Mount, cons
 	}
 	// In non-privileged mode, this fails. Discard the error.
 	setupLoopbackDevices(rootfs)
-	if err := setupDev(rootfs); err != nil {
-		return err
-	}
 	if err := setupPtmx(rootfs, console, mountLabel); err != nil {
 		return err
 	}
@@ -173,30 +170,6 @@ func copyDevNode(rootfs, node string) error {
 	return nil
 }
 
-// setupDev symlinks the current processes pipes into the
-// appropriate destination on the containers rootfs
-func setupDev(rootfs string) error {
-	for _, link := range []struct {
-		from string
-		to   string
-	}{
-		{"/proc/kcore", "/dev/core"},
-		{"/proc/self/fd", "/dev/fd"},
-		{"/proc/self/fd/0", "/dev/stdin"},
-		{"/proc/self/fd/1", "/dev/stdout"},
-		{"/proc/self/fd/2", "/dev/stderr"},
-	} {
-		dest := filepath.Join(rootfs, link.to)
-		if err := os.Remove(dest); err != nil && !os.IsNotExist(err) {
-			return fmt.Errorf("remove %s %s", dest, err)
-		}
-		if err := os.Symlink(link.from, dest); err != nil {
-			return fmt.Errorf("symlink %s %s", dest, err)
-		}
-	}
-	return nil
-}
-
 // setupConsole ensures that the container has a proper /dev/console setup
 func setupConsole(rootfs, console string, mountLabel string) error {
 	oldMask := system.Umask(0000)