diff --git a/daemon/daemon_linux.go b/daemon/daemon_linux.go index 0ae9096522..5355fd4f2d 100644 --- a/daemon/daemon_linux.go +++ b/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() { diff --git a/daemon/daemon_linux_test.go b/daemon/daemon_linux_test.go index 6179c700d0..0439d0bcd7 100644 --- a/daemon/daemon_linux_test.go +++ b/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") + } +}