Пример #1
0
func createLink(socketPath string) (*linkpkg.Link, io.WriteCloser, io.WriteCloser, error) {
	linkStdout := gbytes.NewBuffer()
	linkStderr := gbytes.NewBuffer()
	var l *linkpkg.Link
	var err error
	for i := 0; i < 100; i++ {
		time.Sleep(10 * time.Millisecond)
		l, err = linkpkg.Create(socketPath, linkStdout, linkStderr)
		if err == nil {
			break
		}
	}
	return l, linkStdout, linkStderr, err
}
Пример #2
0
// This is guarded by runningLink so will only run once per Process per garden.
func (p *Process) runLinker() {
	processSock := path.Join(p.containerPath, "processes", fmt.Sprintf("%s.sock", p.ID()))

	link, err := link.Create(processSock, p.stdout, p.stderr)
	if err != nil {
		p.completed(-1, err)
		return
	}

	p.stdin.AddSink(link)

	p.link = link
	close(p.linked)

	p.completed(p.link.Wait())

	// don't leak stdin pipe
	p.stdin.Close()
}
Пример #3
0
	It("can read stdin", func() {
		spawnS, err := gexec.Start(exec.Command(
			iodaemonBinPath,
			"spawn",
			socketPath,
			"bash", "-c", "cat <&0; exit 42",
		), GinkgoWriter, GinkgoWriter)
		Expect(err).ToNot(HaveOccurred())

		defer spawnS.Kill()

		Eventually(spawnS).Should(gbytes.Say("ready\n"))
		Consistently(spawnS).ShouldNot(gbytes.Say("active\n"))

		linkStdout := gbytes.NewBuffer()
		link, err := linkpkg.Create(socketPath, linkStdout, os.Stderr)
		Expect(err).ToNot(HaveOccurred())

		link.Write([]byte("hello\ngoodbye"))
		link.Close()

		Eventually(spawnS).Should(gbytes.Say("active\n"))
		Eventually(linkStdout).Should(gbytes.Say("hello\ngoodbye"))

		Expect(link.Wait()).To(Equal(42))
	})

	It("can read stdin in tty mode", func() {
		spawnS, err := gexec.Start(exec.Command(
			iodaemonBinPath,
			"-tty",
	It("can read stdin", func() {
		spawnS, err := gexec.Start(exec.Command(
			iodaemonBinPath,
			"spawn",
			socketPath,
			"bash", "-c", "cat <&0; exit 42",
		), GinkgoWriter, GinkgoWriter)
		Expect(err).ToNot(HaveOccurred())

		defer spawnS.Kill()

		Eventually(spawnS).Should(gbytes.Say("ready\n"))
		Consistently(spawnS).ShouldNot(gbytes.Say("active\n"))

		linkStdout := gbytes.NewBuffer()
		link, err := linkpkg.Create(socketPath, linkStdout, os.Stderr)
		Expect(err).ToNot(HaveOccurred())

		link.Write([]byte("hello\ngoodbye"))
		link.Close()

		Eventually(spawnS).Should(gbytes.Say("active\n"))
		Eventually(linkStdout).Should(gbytes.Say("hello\ngoodbye"))

		Expect(link.Wait()).To(Equal(42))
	})

	It("can read stdin in tty mode", func() {
		spawnS, err := gexec.Start(exec.Command(
			iodaemonBinPath,
			"-tty",