Merge pull request #2519 from jterry75/various_win_fixes
Various Windows fixes to support the runtime v2 shim workflow
This commit is contained in:
commit
d3887f6764
@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
|
||||||
|
|
||||||
winio "github.com/Microsoft/go-winio"
|
winio "github.com/Microsoft/go-winio"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
@ -41,7 +40,6 @@ func NewFIFOSetInDir(_, id string, terminal bool) (*FIFOSet, error) {
|
|||||||
|
|
||||||
func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
|
func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
|
||||||
var (
|
var (
|
||||||
wg sync.WaitGroup
|
|
||||||
set []io.Closer
|
set []io.Closer
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,9 +83,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
|
|||||||
}(l)
|
}(l)
|
||||||
set = append(set, l)
|
set = append(set, l)
|
||||||
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.L.WithError(err).Errorf("failed to accept stdout connection on %s", fifos.Stdout)
|
log.L.WithError(err).Errorf("failed to accept stdout connection on %s", fifos.Stdout)
|
||||||
@ -115,9 +111,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
|
|||||||
}(l)
|
}(l)
|
||||||
set = append(set, l)
|
set = append(set, l)
|
||||||
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.L.WithError(err).Errorf("failed to accept stderr connection on %s", fifos.Stderr)
|
log.L.WithError(err).Errorf("failed to accept stderr connection on %s", fifos.Stderr)
|
||||||
|
@ -59,15 +59,16 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
|
|
||||||
// NewTask creates a new task
|
// NewTask creates a new task
|
||||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||||
ioCreator := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
|
var ioCreator cio.Creator
|
||||||
if tty {
|
if tty {
|
||||||
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
|
|
||||||
}
|
|
||||||
if nullIO {
|
if nullIO {
|
||||||
if tty {
|
|
||||||
return nil, errors.New("tty and null-io cannot be used together")
|
return nil, errors.New("tty and null-io cannot be used together")
|
||||||
}
|
}
|
||||||
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
|
||||||
|
} else if nullIO {
|
||||||
ioCreator = cio.NullIO
|
ioCreator = cio.NullIO
|
||||||
|
} else {
|
||||||
|
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
|
||||||
}
|
}
|
||||||
return container.NewTask(ctx, ioCreator)
|
return container.NewTask(ctx, ioCreator)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -48,7 +49,25 @@ func SocketAddress(ctx context.Context, id string) (string, error) {
|
|||||||
|
|
||||||
// AnonDialer returns a dialer for a npipe
|
// AnonDialer returns a dialer for a npipe
|
||||||
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
|
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
|
||||||
return winio.DialPipe(address, &timeout)
|
var c net.Conn
|
||||||
|
var lastError error
|
||||||
|
start := time.Now()
|
||||||
|
for {
|
||||||
|
remaining := timeout - time.Now().Sub(start)
|
||||||
|
if remaining <= 0 {
|
||||||
|
lastError = errors.Errorf("timed out waiting for npipe %s", address)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
c, lastError = winio.DialPipe(address, &remaining)
|
||||||
|
if lastError == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !os.IsNotExist(lastError) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
return c, lastError
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSocket returns a new npipe listener
|
// NewSocket returns a new npipe listener
|
||||||
|
Loading…
Reference in New Issue
Block a user