Browse Source

Merge pull request #16643 from chenchun/fix_empty_repository

Do not try to cleanupMounts if daemon.repository is empty
Brian Goff 9 years ago
parent
commit
4ab8514387
2 changed files with 19 additions and 0 deletions
  1. 3 0
      daemon/daemon_linux.go
  2. 16 0
      daemon/daemon_linux_test.go

+ 3 - 0
daemon/daemon_linux.go

@@ -24,6 +24,9 @@ func (daemon *Daemon) cleanupMounts() error {
 }
 
 func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
+	if daemon.repository == "" {
+		return nil
+	}
 	sc := bufio.NewScanner(reader)
 	var errors []string
 	for sc.Scan() {

+ 16 - 0
daemon/daemon_linux_test.go

@@ -56,3 +56,19 @@ func TestCleanupMounts(t *testing.T) {
 		t.Fatalf("Expected to unmount the mqueue")
 	}
 }
+
+func TestNotCleanupMounts(t *testing.T) {
+	d := &Daemon{
+		repository: "",
+	}
+	var unmounted bool
+	unmount := func(target string) error {
+		unmounted = true
+		return nil
+	}
+	mountInfo := `234 232 0:59 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k`
+	d.cleanupMountsFromReader(strings.NewReader(mountInfo), unmount)
+	if unmounted {
+		t.Fatalf("Expected not to clean up /dev/shm")
+	}
+}