rootfs_linux.go
func reOpenDevNull(rootfs string) error {
	var stat, devNullStat syscall.Stat_t
	file, err := os.Open("/dev/null")
	if err != nil {
		return fmt.Errorf("Failed to open /dev/null - %s", err)
	}
	defer file.Close()
	if err := syscall.Fstat(int(file.Fd()), &devNullStat); err != nil {
		return err
	}
	for fd := 0; fd < 3; fd++ {
		if err := syscall.Fstat(fd, &stat); err != nil {
			return err
		}
		if stat.Rdev == devNullStat.Rdev {
			// Close and re-open the fd.
			if err := syscall.Dup3(int(file.Fd()), fd, 0); err != nil {
				return err
			}
		}
	}
	return nil
}
func reOpenDevNull(rootfs string) error {
	var stat, devNullStat syscall.Stat_t
	file, err := os.Open("/dev/null")
	if err != nil {
		return fmt.Errorf("Failed to open /dev/null - %s", err)
	}
	defer file.Close()
	if err := syscall.Fstat(int(file.Fd()), &devNullStat); err != nil {
		return err
	}
	for fd := 0; fd < 3; fd++ {
		if err := syscall.Fstat(fd, &stat); err != nil {
			return err
		}
		if stat.Rdev == devNullStat.Rdev {
			// Close and re-open the fd.
			if err := syscall.Dup3(int(file.Fd()), fd, 0); err != nil {
				return err
			}
		}
	}
	return nil
}
func reOpenDevNull ( rootfs string ) error { var stat , devNullStat syscall . Stat_t file , err := os . Open ( " " ) if err != nil { return fmt . Errorf ( " " , err ) } defer file . Close ( ) if err := syscall . Fstat ( int ( file . Fd ( ) ) , & devNullStat ) ; err != nil { return err } for fd := 0 ; fd < 3 ; fd ++ { if err := syscall . Fstat ( fd , & stat ) ; err != nil { return err } if stat . Rdev == devNullStat . Rdev { // Close and re-open the fd. if err := syscall . Dup3 ( int ( file . Fd ( ) ) , fd , 0 ) ; err != nil { return err } } } return nil }
// If stdin, stdout, and/or stderr are pointing to `/dev/null` in the parent's rootfs
// this method will make them point to `/dev/null` in this container's rootfs.  This
// needs to be called after we chroot/pivot into the container's rootfs so that any
// symlinks are resolved locally.
If stdin stdout and / or stderr are pointing to / dev / null in the parent s rootfs this method will make them point to / dev / null in this container s rootfs . This needs to be called after we chroot / pivot into the container s rootfs so that any symlinks are resolved locally .