Skip to content

Commit

Permalink
Merge pull request #764 from mlaventure/delay-io-closure-until-exit
Browse files Browse the repository at this point in the history
Delay io closure until process exit
  • Loading branch information
crosbymichael authored Apr 25, 2017
2 parents a47bf53 + fbc69f7 commit f1a935c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
dist: trusty
sudo: required

language: go

go:
- 1.8.x
- tip

go_import_path: github.com/containerd/containerd

addons:
apt:
packages:
- apparmor
- libapparmor-dev
- curl

env:
- SECCOMP_VERSION=2.3.1 RUNC_COMMIT=51371867a01c467f08af739783b8beafc154c4d7

install:
- hack/install-seccomp.sh
- hack/install-runc.sh
- go get -u github.com/golang/lint/golint

script:
- make all
- sudo make install
- sudo -E env "PATH=$PATH" "GOPATH=$GOPATH" make test
- sudo -E env "PATH=$PATH" "GOPATH=$GOPATH" make integration-test
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ DOCKER_RUN := docker run --privileged --rm -i $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"

export GOPATH:=$(CURDIR)/vendor:$(GOPATH)

.PHONY: integration-test

all: client daemon shim

static: client-static daemon-static shim-static
Expand Down Expand Up @@ -94,6 +96,10 @@ ifneq ($(wildcard /.dockerenv), )
go test -check.v -check.timeout=$(TEST_TIMEOUT) $(TESTFLAGS) timeout=$(TEST_SUITE_TIMEOUT) github.com/containerd/containerd/integration-test
endif

integration-test:
cd integration-test ; \
go test -check.v -check.timeout=$(TEST_TIMEOUT) $(TESTFLAGS) timeout=$(TEST_SUITE_TIMEOUT) github.com/containerd/containerd/integration-test

bench: shim validate install bundles-rootfs
go test -bench=. -v $(shell go list ./... | grep -v /vendor | grep -v /integration-test) -runtime=$(RUNTIME)

Expand Down
1 change: 1 addition & 0 deletions containerd-shim/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type process struct {
consolePath string
state *processState
runtime string
ioCleanupFn func()
}

func newProcess(id, bundle, runtimeName string) (*process, error) {
Expand Down
27 changes: 19 additions & 8 deletions containerd-shim/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ func (p *process) openIO() error {
return err
}
p.Add(1)
go func() {
io.Copy(stdoutw, master)
p.ioCleanupFn = func() {
master.Close()
stdoutr.Close()
stdoutw.Close()
}
go func() {
io.Copy(stdoutw, master)
p.Done()
}()
return nil
Expand All @@ -74,6 +76,7 @@ func (p *process) openIO() error {
}
p.shimIO = i
// non-tty
ioClosers := make([]io.Closer, 0)
for _, pair := range []struct {
name string
dest func(wc io.WriteCloser, rc io.Closer)
Expand All @@ -85,8 +88,6 @@ func (p *process) openIO() error {
go func() {
io.Copy(wc, i.Stdout)
p.Done()
wc.Close()
rc.Close()
}()
},
},
Expand All @@ -97,8 +98,6 @@ func (p *process) openIO() error {
go func() {
io.Copy(wc, i.Stderr)
p.Done()
wc.Close()
rc.Close()
}()
},
},
Expand All @@ -112,21 +111,33 @@ func (p *process) openIO() error {
return fmt.Errorf("containerd-shim: opening %s failed: %s", pair.name, err)
}
pair.dest(fw, fr)
ioClosers = append(ioClosers, fw, fr)
}

f, err := fifo.OpenFifo(ctx, p.state.Stdin, syscall.O_RDONLY, 0)
if err != nil {
return fmt.Errorf("containerd-shim: opening %s failed: %s", p.state.Stdin, err)
}
ioClosers = append(ioClosers, i.Stdin, f)
p.ioCleanupFn = func() {
for _, c := range ioClosers {
c.Close()
}
}
go func() {
io.Copy(i.Stdin, f)
i.Stdin.Close()
f.Close()
}()

return nil
}

func (p *process) Wait() {
p.WaitGroup.Wait()
if p.ioCleanupFn != nil {
p.ioCleanupFn()
}
}

func (p *process) killAll() error {
if !p.state.Exec {
cmd := exec.Command(p.runtime, append(p.state.RuntimeArgs, "kill", "--all", p.id, "SIGKILL")...)
Expand Down
10 changes: 10 additions & 0 deletions hack/install-runc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

export GOPATH="$(mktemp -d)"
git clone git://github.com/docker/runc.git "$GOPATH/src/github.com/opencontainers/runc"
cd "$GOPATH/src/github.com/opencontainers/runc"
git checkout -q "$RUNC_COMMIT"
make BUILDTAGS="seccomp apparmor selinux"
sudo make install
17 changes: 17 additions & 0 deletions hack/install-seccomp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e
set -x

export SECCOMP_PATH="$(mktemp -d)"

curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \
| tar -xzC "$SECCOMP_PATH" --strip-components=1
(
cd "$SECCOMP_PATH"
./configure --prefix=/usr/local
make
sudo make install
sudo ldconfig
)
rm -rf "$SECCOMP_PATH"

0 comments on commit f1a935c

Please sign in to comment.