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
}
Exemple #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("%d.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()
}
Exemple #3
0
	AfterEach(func() {
		Expect(fakeServer.Stop()).To(Succeed())

		Expect(os.RemoveAll(path.Base(unixSockerPath))).To(Succeed())
	})

	Describe("Create", func() {
		Context("when files are not provided", func() {
			BeforeEach(func() {
				fakeServer.SetConnectionHandler(func(conn net.Conn) {
					conn.Close()
				})
			})

			It("returns an error", func() {
				_, err := linkpkg.Create(unixSockerPath, stdout, stderr)
				Expect(err).To(HaveOccurred())
			})
		})

		Context("when files are provided", func() {
			AfterEach(func() {
				stdoutW.Close()
				stderrW.Close()
				statusW.Close()
			})

			It("succeeds", func() {
				_, err := linkpkg.Create(unixSockerPath, stdout, stderr)
				Expect(err).ToNot(HaveOccurred())
			})
	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",