コード例 #1
0
ファイル: direct_process.go プロジェクト: xingdl2007/os
func (d *directProcess) openIO() (*os.File, *os.File, *os.File, error) {
	uid, gid, err := getRootIDs(d.specs)
	if err != nil {
		return nil, nil, nil, err
	}

	if d.spec.Terminal {
		console, err := libcontainer.NewConsole(uid, gid)
		if err != nil {
			return nil, nil, nil, err
		}
		d.console = console
		d.consolePath = console.Path()
		stdin, err := os.OpenFile(d.stdio.Stdin, syscall.O_RDONLY, 0)
		if err != nil {
			return nil, nil, nil, err
		}
		go io.Copy(console, stdin)
		stdout, err := os.OpenFile(d.stdio.Stdout, syscall.O_RDWR, 0)
		if err != nil {
			return nil, nil, nil, err
		}
		d.Add(1)
		go func() {
			io.Copy(stdout, console)
			console.Close()
			d.Done()
		}()
		d.io.stdin = stdin
		d.io.stdout = stdout
		d.io.stderr = stdout
		return nil, nil, nil, nil
	}

	stdin, err := os.OpenFile(d.stdio.Stdin, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
	if err != nil {
		return nil, nil, nil, err
	}

	stdout, err := os.OpenFile(d.stdio.Stdout, syscall.O_RDWR, 0)
	if err != nil {
		return nil, nil, nil, err
	}

	stderr, err := os.OpenFile(d.stdio.Stderr, syscall.O_RDWR, 0)
	if err != nil {
		return nil, nil, nil, err
	}

	d.io.stdin = stdin
	d.io.stdout = stdout
	d.io.stderr = stderr
	return stdin, stdout, stderr, nil
}
コード例 #2
0
ファイル: container.go プロジェクト: mynameismevin/containerd
func attachTty(consolePath *string) error {
	console, err := libcontainer.NewConsole(os.Getuid(), os.Getgid())
	if err != nil {
		return err
	}
	*consolePath = console.Path()
	stdin = console
	go func() {
		io.Copy(os.Stdout, console)
		console.Close()
	}()
	s, err := term.SetRawTerminal(os.Stdin.Fd())
	if err != nil {
		return err
	}
	state = s
	return nil
}