github.com/cdoern/storage@v1.12.13/drivers/chroot_unix.go (about)

     1  // +build linux darwin freebsd solaris
     2  
     3  package graphdriver
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"syscall"
     9  )
    10  
    11  // chrootOrChdir() is either a chdir() to the specified path, or a chroot() to the
    12  // specified path followed by chdir() to the new root directory
    13  func chrootOrChdir(path string) error {
    14  	if err := syscall.Chroot(path); err != nil {
    15  		return fmt.Errorf("error chrooting to %q: %v", path, err)
    16  	}
    17  	if err := syscall.Chdir(string(os.PathSeparator)); err != nil {
    18  		return fmt.Errorf("error changing to %q: %v", path, err)
    19  	}
    20  	return nil
    21  }