Merge pull request #938 from dmcgowan/client-windows-compile

Fix windows build for client
This commit is contained in:
Kenfe-Mickaël Laventure 2017-05-31 11:58:36 -07:00 committed by GitHub
commit 95446e8f43
7 changed files with 173 additions and 67 deletions

View File

@ -1,3 +1,5 @@
// +build !windows
package containerd package containerd
import ( import (

63
io.go
View File

@ -2,15 +2,11 @@ package containerd
import ( import (
"bytes" "bytes"
"context"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
"syscall"
"github.com/containerd/fifo"
) )
type IO struct { type IO struct {
@ -111,65 +107,6 @@ type ioSet struct {
out, err io.Writer out, err io.Writer
} }
func copyIO(fifos *fifoSet, ioset *ioSet, tty bool) (closer io.Closer, err error) {
var (
f io.ReadWriteCloser
ctx = context.Background()
wg = &sync.WaitGroup{}
)
if f, err = fifo.OpenFifo(ctx, fifos.in, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
return nil, err
}
defer func(c io.Closer) {
if err != nil {
c.Close()
}
}(f)
go func(w io.WriteCloser) {
io.Copy(w, ioset.in)
w.Close()
}(f)
if f, err = fifo.OpenFifo(ctx, fifos.out, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
return nil, err
}
defer func(c io.Closer) {
if err != nil {
c.Close()
}
}(f)
wg.Add(1)
go func(r io.ReadCloser) {
io.Copy(ioset.out, r)
r.Close()
wg.Done()
}(f)
if f, err = fifo.OpenFifo(ctx, fifos.err, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
return nil, err
}
defer func(c io.Closer) {
if err != nil {
c.Close()
}
}(f)
if !tty {
wg.Add(1)
go func(r io.ReadCloser) {
io.Copy(ioset.err, r)
r.Close()
wg.Done()
}(f)
}
return &wgCloser{
wg: wg,
dir: fifos.dir,
}, nil
}
type wgCloser struct { type wgCloser struct {
wg *sync.WaitGroup wg *sync.WaitGroup
dir string dir string

71
io_unix.go Normal file
View File

@ -0,0 +1,71 @@
// +build !windows
package containerd
import (
"context"
"io"
"sync"
"syscall"
"github.com/containerd/fifo"
)
func copyIO(fifos *fifoSet, ioset *ioSet, tty bool) (closer io.Closer, err error) {
var (
f io.ReadWriteCloser
ctx = context.Background()
wg = &sync.WaitGroup{}
)
if f, err = fifo.OpenFifo(ctx, fifos.in, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
return nil, err
}
defer func(c io.Closer) {
if err != nil {
c.Close()
}
}(f)
go func(w io.WriteCloser) {
io.Copy(w, ioset.in)
w.Close()
}(f)
if f, err = fifo.OpenFifo(ctx, fifos.out, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
return nil, err
}
defer func(c io.Closer) {
if err != nil {
c.Close()
}
}(f)
wg.Add(1)
go func(r io.ReadCloser) {
io.Copy(ioset.out, r)
r.Close()
wg.Done()
}(f)
if f, err = fifo.OpenFifo(ctx, fifos.err, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
return nil, err
}
defer func(c io.Closer) {
if err != nil {
c.Close()
}
}(f)
if !tty {
wg.Add(1)
go func(r io.ReadCloser) {
io.Copy(ioset.err, r)
r.Close()
wg.Done()
}(f)
}
return &wgCloser{
wg: wg,
dir: fifos.dir,
}, nil
}

93
io_windows.go Normal file
View File

@ -0,0 +1,93 @@
package containerd
import (
"io"
"net"
"sync"
winio "github.com/Microsoft/go-winio"
"github.com/containerd/containerd/log"
"github.com/pkg/errors"
)
func copyIO(fifos *fifoSet, ioset *ioSet, tty bool) (closer io.Closer, err error) {
var wg sync.WaitGroup
if fifos.in != "" {
l, err := winio.ListenPipe(fifos.in, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to create stdin pipe %s", fifos.in)
}
defer func(l net.Listener) {
if err != nil {
l.Close()
}
}(l)
go func() {
c, err := l.Accept()
if err != nil {
log.L.WithError(err).Errorf("failed to accept stdin connection on %s", fifos.in)
return
}
io.Copy(c, ioset.in)
c.Close()
l.Close()
}()
}
if fifos.out != "" {
l, err := winio.ListenPipe(fifos.out, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to create stdin pipe %s", fifos.out)
}
defer func(l net.Listener) {
if err != nil {
l.Close()
}
}(l)
wg.Add(1)
go func() {
defer wg.Done()
c, err := l.Accept()
if err != nil {
log.L.WithError(err).Errorf("failed to accept stdout connection on %s", fifos.out)
return
}
io.Copy(ioset.out, c)
c.Close()
l.Close()
}()
}
if !tty && fifos.err != "" {
l, err := winio.ListenPipe(fifos.err, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to create stderr pipe %s", fifos.err)
}
defer func(l net.Listener) {
if err != nil {
l.Close()
}
}(l)
wg.Add(1)
go func() {
defer wg.Done()
c, err := l.Accept()
if err != nil {
log.L.WithError(err).Errorf("failed to accept stderr connection on %s", fifos.err)
return
}
io.Copy(ioset.err, c)
c.Close()
l.Close()
}()
}
return &wgCloser{
wg: &wg,
dir: fifos.dir,
}, nil
}

View File

@ -1,3 +1,5 @@
// +build !windows
package containerd package containerd
import ( import (

View File

@ -1,3 +1,5 @@
// +build !windows
package containerd package containerd
import "testing" import "testing"

View File

@ -22,7 +22,6 @@ func createDefaultSpec() (*specs.Spec, error) {
}, },
Root: specs.Root{}, Root: specs.Root{},
Process: specs.Process{ Process: specs.Process{
Env: config.Env,
ConsoleSize: specs.Box{ ConsoleSize: specs.Box{
Width: 80, Width: 80,
Height: 20, Height: 20,
@ -70,10 +69,10 @@ func WithImageConfig(ctx context.Context, i Image) SpecOpts {
} }
func WithTTY(width, height int) SpecOpts { func WithTTY(width, height int) SpecOpts {
func(s *specs.Spec) error { return func(s *specs.Spec) error {
s.Process.Terminal = true s.Process.Terminal = true
s.Process.ConsoleSize.Width = width s.Process.ConsoleSize.Width = uint(width)
s.Process.ConsoleSize.Height = height s.Process.ConsoleSize.Height = uint(height)
return nil return nil
} }
} }